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 13:46:13 +03:00
|
|
|
func (d *defaultOptions) Options() Options {
|
|
|
|
return d
|
2019-06-06 13:32:38 +03:00
|
|
|
}
|
|
|
|
|
2019-06-06 13:46:13 +03:00
|
|
|
func (d *defaultOptions) Value(k interface{}) (interface{}, bool) {
|
|
|
|
if d.opts == nil {
|
|
|
|
d.opts = new(Values)
|
2019-06-06 13:32:38 +03:00
|
|
|
}
|
2019-06-06 13:46:13 +03:00
|
|
|
return d.opts.Get(k)
|
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
|
|
|
}
|