github.com/searKing/golang/go@v1.2.117/net/resolver/pick_options.go (about) 1 // Code generated by "go-option -type Pick"; DO NOT EDIT. 2 3 package resolver 4 5 // A PickOption sets options. 6 type PickOption interface { 7 apply(*Pick) 8 } 9 10 // EmptyPickOption does not alter the configuration. It can be embedded 11 // in another structure to build custom options. 12 // 13 // This API is EXPERIMENTAL. 14 type EmptyPickOption struct{} 15 16 func (EmptyPickOption) apply(*Pick) {} 17 18 // PickOptionFunc wraps a function that modifies Pick into an 19 // implementation of the PickOption interface. 20 type PickOptionFunc func(*Pick) 21 22 func (f PickOptionFunc) apply(do *Pick) { 23 f(do) 24 } 25 26 // sample code for option, default for nothing to change 27 func _PickOptionWithDefault() PickOption { 28 return PickOptionFunc(func(*Pick) { 29 // nothing to change 30 }) 31 } 32 func (o *Pick) ApplyOptions(options ...PickOption) *Pick { 33 for _, opt := range options { 34 if opt == nil { 35 continue 36 } 37 opt.apply(o) 38 } 39 return o 40 }