-
Notifications
You must be signed in to change notification settings - Fork 1
/
source.go
59 lines (50 loc) · 1.7 KB
/
source.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
49
50
51
52
53
54
55
56
57
58
59
package source
import (
"errors"
"github.com/alexfalkowski/go-service/transport/http"
ht "github.com/alexfalkowski/go-service/transport/http/telemetry/tracer"
"github.com/alexfalkowski/konfig/source/configurator"
"github.com/alexfalkowski/konfig/source/configurator/folder"
"github.com/alexfalkowski/konfig/source/configurator/git"
gt "github.com/alexfalkowski/konfig/source/configurator/git/telemetry/tracer"
"github.com/alexfalkowski/konfig/source/configurator/s3"
st "github.com/alexfalkowski/konfig/source/configurator/s3/telemetry/tracer"
"go.opentelemetry.io/otel/metric"
"go.uber.org/fx"
"go.uber.org/zap"
)
// ErrNoConfigurator is defined in the config.
var ErrNoConfigurator = errors.New("no configurator")
// ConfiguratorParams for source.
type ConfiguratorParams struct {
fx.In
Config *Config
HTTPConfig *http.Config
Logger *zap.Logger
HTTPTracer ht.Tracer
Meter metric.Meter
GitTracer gt.Tracer
S3Tracer st.Tracer
}
// NewConfigurator for source.
func NewConfigurator(params ConfiguratorParams) (configurator.Configurator, error) {
client, err := http.NewClient(params.HTTPConfig,
http.WithClientLogger(params.Logger), http.WithClientTracer(params.HTTPTracer),
http.WithClientMetrics(params.Meter),
)
if err != nil {
return nil, err
}
var configurator configurator.Configurator
switch {
case params.Config.IsFolder():
configurator = folder.NewConfigurator(params.Config.Folder)
case params.Config.IsGit():
configurator = git.NewConfigurator(params.Config.Git, params.GitTracer, client)
case params.Config.IsS3():
configurator = s3.NewConfigurator(params.Config.S3, params.S3Tracer, client)
default:
return nil, ErrNoConfigurator
}
return configurator, nil
}