-
Notifications
You must be signed in to change notification settings - Fork 1
/
source.go
57 lines (48 loc) · 1.79 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
package source
import (
"errors"
"github.com/alexfalkowski/go-service/transport/http"
"github.com/alexfalkowski/go-service/transport/http/metrics/prometheus"
hopentracing "github.com/alexfalkowski/go-service/transport/http/trace/opentracing"
"github.com/alexfalkowski/konfig/source/configurator"
"github.com/alexfalkowski/konfig/source/configurator/folder"
"github.com/alexfalkowski/konfig/source/configurator/git"
gopentracing "github.com/alexfalkowski/konfig/source/configurator/git/opentracing"
"github.com/alexfalkowski/konfig/source/configurator/s3"
sopentracing "github.com/alexfalkowski/konfig/source/configurator/s3/opentracing"
"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 hopentracing.Tracer
Metrics *prometheus.ClientMetrics
GitTracer gopentracing.Tracer
S3Tracer sopentracing.Tracer
}
// NewConfigurator for source.
func NewConfigurator(params ConfiguratorParams) (configurator.Configurator, error) {
client := http.NewClient(
http.ClientParams{Config: params.HTTPConfig},
http.WithClientLogger(params.Logger), http.WithClientTracer(params.HTTPTracer),
http.WithClientMetrics(params.Metrics),
)
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
}