-
Notifications
You must be signed in to change notification settings - Fork 177
/
picfit.go
48 lines (38 loc) · 1.13 KB
/
picfit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package picfit
import (
"context"
"log/slog"
"github.com/thoas/picfit/constants"
"github.com/thoas/picfit/config"
"github.com/thoas/picfit/engine"
"github.com/thoas/picfit/logger"
"github.com/thoas/picfit/storage"
"github.com/thoas/picfit/store"
)
// NewProcessor returns a Processor instance from a config.Config instance
func NewProcessor(ctx context.Context, cfg *config.Config) (*Processor, error) {
cfg.Logger.ContextKeys = []string{constants.RequestIDCtx}
log := logger.New(cfg.Logger)
sourceStorage, destinationStorage, err := storage.New(ctx,
log.With(slog.String("logger", "storage")), cfg.Storage)
if err != nil {
return nil, err
}
s, err := store.New(ctx,
log.With(slog.String("logger", "store")),
cfg.KVStore)
if err != nil {
return nil, err
}
e := engine.New(*cfg.Engine, log.With(slog.String("logger", "engine")))
log.InfoContext(ctx, "Image engine configured",
slog.String("engine", e.String()))
return &Processor{
Logger: log,
config: cfg,
destinationStorage: destinationStorage,
engine: e,
sourceStorage: sourceStorage,
store: s,
}, nil
}