gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/config/source/options.go (about) 1 package source 2 3 import ( 4 "context" 5 6 "gitee.com/liuxuezhan/go-micro-v1.18.0/config/encoder" 7 "gitee.com/liuxuezhan/go-micro-v1.18.0/config/encoder/json" 8 ) 9 10 type Options struct { 11 // Encoder 12 Encoder encoder.Encoder 13 14 // for alternative data 15 Context context.Context 16 } 17 18 type Option func(o *Options) 19 20 func NewOptions(opts ...Option) Options { 21 options := Options{ 22 Encoder: json.NewEncoder(), 23 Context: context.Background(), 24 } 25 26 for _, o := range opts { 27 o(&options) 28 } 29 30 return options 31 } 32 33 // WithEncoder sets the source encoder 34 func WithEncoder(e encoder.Encoder) Option { 35 return func(o *Options) { 36 o.Encoder = e 37 } 38 }