-
Notifications
You must be signed in to change notification settings - Fork 3
/
configurator.go
82 lines (67 loc) · 1.92 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
package config
import (
"github.com/alexfalkowski/go-service/cache/redis"
"github.com/alexfalkowski/go-service/cache/ristretto"
"github.com/alexfalkowski/go-service/cmd"
"github.com/alexfalkowski/go-service/database/sql/pg"
"github.com/alexfalkowski/go-service/security/auth0"
"github.com/alexfalkowski/go-service/telemetry/tracer"
"github.com/alexfalkowski/go-service/transport"
"github.com/alexfalkowski/go-service/transport/grpc"
"github.com/alexfalkowski/go-service/transport/http"
"github.com/alexfalkowski/go-service/transport/nsq"
"go.uber.org/fx"
)
// 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
TracerConfig() *tracer.Config
TransportConfig() *transport.Config
GRPCConfig() *grpc.Config
HTTPConfig() *http.Config
NSQConfig() *nsq.Config
}
// UnmarshalParams for config.
type UnmarshalParams struct {
fx.In
Configurator Configurator
Config *cmd.InputConfig
}
// Unmarshal to config.
func Unmarshal(params UnmarshalParams) error {
return params.Config.Unmarshal(params.Configurator)
}
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 tracerConfig(cfg Configurator) *tracer.Config {
return cfg.TracerConfig()
}
func transportConfig(cfg Configurator) *transport.Config {
return cfg.TransportConfig()
}
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()
}