-
Notifications
You must be signed in to change notification settings - Fork 3
/
configurator.go
83 lines (68 loc) · 1.86 KB
/
configurator.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package config
import (
"github.com/alexfalkowski/go-service/cache/redis"
"github.com/alexfalkowski/go-service/cache/ristretto"
"github.com/alexfalkowski/go-service/database/sql/pg"
"github.com/alexfalkowski/go-service/security/auth0"
"github.com/alexfalkowski/go-service/trace/opentracing/datadog"
"github.com/alexfalkowski/go-service/trace/opentracing/jaeger"
"github.com/alexfalkowski/go-service/transport/grpc"
"github.com/alexfalkowski/go-service/transport/http"
"github.com/alexfalkowski/go-service/transport/nsq"
"gopkg.in/yaml.v3"
)
// NewConfigurator for config.
func NewConfigurator() Configurator {
return &Config{}
}
// Configurator for config.
type Configurator interface {
RedisConfig() *redis.Config
RistrettoConfig() *ristretto.Config
Auth0Config() *auth0.Config
PGConfig() *pg.Config
DatadogConfig() *datadog.Config
JaegerConfig() *jaeger.Config
GRPCConfig() *grpc.Config
HTTPConfig() *http.Config
NSQConfig() *nsq.Config
}
// UnmarshalFromFile to config.
func UnmarshalFromFile(cfg Configurator) error {
bytes, err := ReadFile()
if err != nil {
return err
}
err = yaml.Unmarshal(bytes, cfg)
if err != nil {
return err
}
return nil
}
func redisConfig(cfg Configurator) *redis.Config {
return cfg.RedisConfig()
}
func ristrettoConfig(cfg Configurator) *ristretto.Config {
return cfg.RistrettoConfig()
}
func auth0Config(cfg Configurator) *auth0.Config {
return cfg.Auth0Config()
}
func pgConfig(cfg Configurator) *pg.Config {
return cfg.PGConfig()
}
func datadogConfig(cfg Configurator) *datadog.Config {
return cfg.DatadogConfig()
}
func jaegerConfig(cfg Configurator) *jaeger.Config {
return cfg.JaegerConfig()
}
func grpcConfig(cfg Configurator) *grpc.Config {
return cfg.GRPCConfig()
}
func httpConfig(cfg Configurator) *http.Config {
return cfg.HTTPConfig()
}
func nsqConfig(cfg Configurator) *nsq.Config {
return cfg.NSQConfig()
}