-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
62 lines (49 loc) · 1.4 KB
/
config.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
package config
import (
"github.com/alexfalkowski/go-service/cmd"
"github.com/alexfalkowski/go-service/config"
"github.com/alexfalkowski/migrieren/client"
v1 "github.com/alexfalkowski/migrieren/client/v1/config"
"github.com/alexfalkowski/migrieren/health"
"github.com/alexfalkowski/migrieren/migrate"
)
// NewConfigurator for config.
func NewConfig(i *cmd.InputConfig) (*Config, error) {
c := &Config{}
return c, i.Unmarshal(c)
}
// IsEnabled for config.
func IsEnabled(cfg *Config) bool {
return cfg != nil
}
// Config for the service.
type Config struct {
Client *client.Config `yaml:"client,omitempty" json:"client,omitempty" toml:"client,omitempty"`
Health *health.Config `yaml:"health,omitempty" json:"health,omitempty" toml:"health,omitempty"`
Migrate *migrate.Config `yaml:"migrate,omitempty" json:"migrate,omitempty" toml:"migrate,omitempty"`
*config.Config `yaml:",inline" json:",inline" toml:",inline"`
}
func decorateConfig(cfg *Config) *config.Config {
if !IsEnabled(cfg) {
return nil
}
return cfg.Config
}
func v1ClientConfig(cfg *Config) *v1.Config {
if !IsEnabled(cfg) || !client.IsEnabled(cfg.Client) {
return nil
}
return cfg.Client.V1
}
func healthConfig(cfg *Config) *health.Config {
if !IsEnabled(cfg) {
return nil
}
return cfg.Health
}
func migrateConfig(cfg *Config) *migrate.Config {
if !IsEnabled(cfg) {
return nil
}
return cfg.Migrate
}