This is probably temporaly, it would be better in the future to have a abstraction on top of the S3 bucket, similar to the database abstraction.
65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"log/slog"
|
|
|
|
"forge.capytal.company/capytalcode/project-comicverse/database"
|
|
"forge.capytal.company/loreddev/x/tinyssert"
|
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
|
)
|
|
|
|
type Service struct {
|
|
db *database.Database
|
|
s3 *s3.Client
|
|
bucket string
|
|
|
|
ctx context.Context
|
|
|
|
assert tinyssert.Assertions
|
|
log *slog.Logger
|
|
}
|
|
|
|
func New(cfg Config) (*Service, error) {
|
|
if cfg.DB == nil {
|
|
return nil, errors.New("database should not be a nil pointer")
|
|
}
|
|
if cfg.S3 == nil {
|
|
return nil, errors.New("s3 client should not be a nil pointer")
|
|
}
|
|
if cfg.Bucket == "" {
|
|
return nil, errors.New("bucket should not be a empty string")
|
|
}
|
|
if cfg.Context == nil {
|
|
return nil, errors.New("context should not be a nil interface")
|
|
}
|
|
if cfg.Assertions == nil {
|
|
return nil, errors.New("assertions should not be a nil interface")
|
|
}
|
|
if cfg.Logger == nil {
|
|
return nil, errors.New("logger should not be a nil pointer")
|
|
}
|
|
return &Service{
|
|
db: cfg.DB,
|
|
s3: cfg.S3,
|
|
bucket: cfg.Bucket,
|
|
|
|
ctx: cfg.Context,
|
|
|
|
assert: cfg.Assertions,
|
|
log: cfg.Logger,
|
|
}, nil
|
|
}
|
|
|
|
type Config struct {
|
|
DB *database.Database
|
|
S3 *s3.Client
|
|
Bucket string
|
|
|
|
Context context.Context
|
|
|
|
Assertions tinyssert.Assertions
|
|
Logger *slog.Logger
|
|
}
|