gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/config/options/default.go (about)

     1  package options
     2  
     3  type defaultOptions struct {
     4  	opts *Values
     5  }
     6  
     7  type stringKey struct{}
     8  
     9  func (d *defaultOptions) Init(opts ...Option) error {
    10  	if d.opts == nil {
    11  		d.opts = new(Values)
    12  	}
    13  	for _, o := range opts {
    14  		if err := d.opts.Option(o); err != nil {
    15  			return err
    16  		}
    17  	}
    18  	return nil
    19  }
    20  
    21  func (d *defaultOptions) Values() *Values {
    22  	return d.opts
    23  }
    24  
    25  func (d *defaultOptions) String() string {
    26  	if d.opts == nil {
    27  		d.opts = new(Values)
    28  	}
    29  	n, ok := d.opts.Get(stringKey{})
    30  	if ok {
    31  		return n.(string)
    32  	}
    33  	return "Values"
    34  }