diff options
author | Wolfy-J <[email protected]> | 2018-09-23 14:52:55 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-09-23 14:52:55 +0300 |
commit | 19d88fc879ba403347726138eb532fb85d38168e (patch) | |
tree | c93c9ddd7a6fe7be3b884458b3ad8e9f4c9b19ec /service/container.go | |
parent | bd046974b969af381b3a50513d9f3ab453ed8bbf (diff) |
default configs
Diffstat (limited to 'service/container.go')
-rw-r--r-- | service/container.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/service/container.go b/service/container.go index 861e1aac..fc1012c8 100644 --- a/service/container.go +++ b/service/container.go @@ -66,6 +66,11 @@ type HydrateConfig interface { Hydrate(cfg Config) error } +type DefaultsConfig interface { + // InitDefaults allows to init blank config with pre-defined set of default values. + InitDefaults() error +} + type container struct { log logrus.FieldLogger mu sync.Mutex @@ -257,11 +262,19 @@ func (c *container) resolveValues(s interface{}, m reflect.Method, cfg Config) ( values = append(values, reflect.ValueOf(c.log)) case v.Implements(reflect.TypeOf((*HydrateConfig)(nil)).Elem()): // injectable config - if cfg == nil { + sc := reflect.New(v.Elem()) + + if dsc, ok := sc.Interface().(DefaultsConfig); ok { + dsc.InitDefaults() + if cfg == nil { + values = append(values, sc) + continue + } + + } else if cfg == nil { return nil, errNoConfig } - sc := reflect.New(v.Elem()) if err := sc.Interface().(HydrateConfig).Hydrate(cfg); err != nil { return nil, err } |