-
Notifications
You must be signed in to change notification settings - Fork 1
/
source.go
51 lines (43 loc) · 1.41 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
package source
import (
"errors"
"github.com/alexfalkowski/go-service/env"
"github.com/alexfalkowski/konfig/source/configurator"
"github.com/alexfalkowski/konfig/source/configurator/folder"
"github.com/alexfalkowski/konfig/source/configurator/git"
cs3 "github.com/alexfalkowski/konfig/source/configurator/s3"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/google/go-github/v62/github"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/trace"
"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
S3Client *s3.Client
GitClient *github.Client
Logger *zap.Logger
Tracer trace.Tracer
Meter metric.Meter
UserAgent env.UserAgent
}
// NewConfigurator for source.
func NewConfigurator(params ConfiguratorParams) (configurator.Configurator, error) {
var configurator configurator.Configurator
switch {
case params.Config.IsFolder():
configurator = folder.NewConfigurator(params.Config.Folder, params.Tracer)
case params.Config.IsGit():
configurator = git.NewConfigurator(params.GitClient, params.Config.Git, params.Tracer)
case params.Config.IsS3():
configurator = cs3.NewConfigurator(params.S3Client, params.Config.S3, params.Tracer)
default:
return nil, ErrNoConfigurator
}
return configurator, nil
}