micro/options/default.go
2019-06-06 17:54:30 +01:00

42 lines
664 B
Go

package options
type defaultOptions struct {
opts *Values
}
type stringKey struct{}
func (d *defaultOptions) Init(opts ...Option) error {
if d.opts == nil {
d.opts = new(Values)
}
for _, o := range opts {
if err := d.opts.Option(o); err != nil {
return err
}
}
return nil
}
func (d *defaultOptions) Options() Options {
return d
}
func (d *defaultOptions) Value(k interface{}) (interface{}, bool) {
if d.opts == nil {
d.opts = new(Values)
}
return d.opts.Get(k)
}
func (d *defaultOptions) String() string {
if d.opts == nil {
d.opts = new(Values)
}
n, ok := d.opts.Get(stringKey{})
if ok {
return n.(string)
}
return "Values"
}