github.com/sandwich-go/boost@v1.3.29/xchan/gen_options_optiongen.go (about) 1 // Code generated by optiongen. DO NOT EDIT. 2 // optiongen: github.com/timestee/optiongen 3 4 package xchan 5 6 // Options should use NewOptions to initialize it 7 type Options struct { 8 CallbackOnBufCount int64 9 Callback func(bufCount int64) 10 } 11 12 // NewOptions new Options 13 func NewOptions(opts ...Option) *Options { 14 cc := newDefaultOptions() 15 for _, opt := range opts { 16 opt(cc) 17 } 18 if watchDogOptions != nil { 19 watchDogOptions(cc) 20 } 21 return cc 22 } 23 24 // ApplyOption apply multiple new option 25 func (cc *Options) ApplyOption(opts ...Option) { 26 for _, opt := range opts { 27 opt(cc) 28 } 29 } 30 31 // Option option func 32 type Option func(cc *Options) 33 34 // WithCallbackOnBufCount option func for filed CallbackOnBufCount 35 func WithCallbackOnBufCount(v int64) Option { 36 return func(cc *Options) { 37 cc.CallbackOnBufCount = v 38 } 39 } 40 41 // WithCallback option func for filed Callback 42 func WithCallback(v func(bufCount int64)) Option { 43 return func(cc *Options) { 44 cc.Callback = v 45 } 46 } 47 48 // InstallOptionsWatchDog the installed func will called when NewOptions called 49 func InstallOptionsWatchDog(dog func(cc *Options)) { watchDogOptions = dog } 50 51 // watchDogOptions global watch dog 52 var watchDogOptions func(cc *Options) 53 54 // newDefaultOptions new default Options 55 func newDefaultOptions() *Options { 56 cc := &Options{} 57 58 for _, opt := range [...]Option{ 59 WithCallbackOnBufCount(0), 60 WithCallback(nil), 61 } { 62 opt(cc) 63 } 64 65 return cc 66 } 67 68 // all getter func 69 func (cc *Options) GetCallbackOnBufCount() int64 { return cc.CallbackOnBufCount } 70 func (cc *Options) GetCallback() func(bufCount int64) { return cc.Callback } 71 72 // OptionsVisitor visitor interface for Options 73 type OptionsVisitor interface { 74 GetCallbackOnBufCount() int64 75 GetCallback() func(bufCount int64) 76 } 77 78 // OptionsInterface visitor + ApplyOption interface for Options 79 type OptionsInterface interface { 80 OptionsVisitor 81 ApplyOption(...Option) 82 }