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