-
Notifications
You must be signed in to change notification settings - Fork 1
/
source.go
43 lines (32 loc) · 1.03 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
package source
import (
"errors"
"github.com/alexfalkowski/konfig/source/configurator"
"github.com/alexfalkowski/konfig/source/configurator/folder"
"github.com/alexfalkowski/konfig/source/configurator/git"
"github.com/alexfalkowski/konfig/source/configurator/trace/opentracing"
"go.uber.org/fx"
)
// ErrNoConfigurator is defined in the config.
var ErrNoConfigurator = errors.New("no configurator")
// ConfiguratorParams for source.
type ConfiguratorParams struct {
fx.In
Config *Config
Tracer opentracing.Tracer
}
// NewConfigurator for source.
func NewConfigurator(params ConfiguratorParams) (configurator.Configurator, error) {
var configurator configurator.Configurator
if params.Config.IsGit() {
configurator = git.NewConfigurator(¶ms.Config.Git, params.Tracer)
}
if params.Config.IsFolder() {
configurator = folder.NewConfigurator(¶ms.Config.Folder)
}
if configurator == nil {
return nil, ErrNoConfigurator
}
configurator = opentracing.NewConfigurator(configurator, params.Tracer)
return configurator, nil
}