micro/config/options/default.go

35 lines
529 B
Go
Raw Normal View History

2019-06-06 19:54:30 +03:00
package options
2019-06-06 13:32:38 +03:00
2019-06-06 13:46:13 +03:00
type defaultOptions struct {
opts *Values
2019-06-06 13:32:38 +03:00
}
type stringKey struct{}
2019-06-06 13:46:13 +03:00
func (d *defaultOptions) Init(opts ...Option) error {
if d.opts == nil {
d.opts = new(Values)
2019-06-06 13:32:38 +03:00
}
for _, o := range opts {
2019-06-06 13:46:13 +03:00
if err := d.opts.Option(o); err != nil {
2019-06-06 13:32:38 +03:00
return err
}
}
return nil
}
2019-06-06 23:45:28 +03:00
func (d *defaultOptions) Values() *Values {
return d.opts
2019-06-06 13:32:38 +03:00
}
2019-06-06 13:46:13 +03:00
func (d *defaultOptions) String() string {
if d.opts == nil {
d.opts = new(Values)
2019-06-06 13:32:38 +03:00
}
2019-06-06 13:46:13 +03:00
n, ok := d.opts.Get(stringKey{})
2019-06-06 13:32:38 +03:00
if ok {
return n.(string)
}
2019-06-06 13:46:13 +03:00
return "Values"
2019-06-06 13:32:38 +03:00
}