package configure import ( "go_dreamfactory/lego/utils/mapstructure" ) type Option func(*Options) type Options struct { ConfigurePath string //配置中心路径 CheckInterval int //配置文件更新检查间隔时间 单位秒 } func Set_ConfigurePath(v string) Option { return func(o *Options) { o.ConfigurePath = v } } func Set_CheckInterval(v int) Option { return func(o *Options) { o.CheckInterval = v } } func newOptions(config map[string]interface{}, opts ...Option) (Options, error) { options := Options{ CheckInterval: 60, } if config != nil { mapstructure.Decode(config, &options) } for _, o := range opts { o(&options) } return options, nil } func newOptionsByOption(opts ...Option) (Options, error) { options := Options{ CheckInterval: 60, } for _, o := range opts { o(&options) } return options, nil } func SetConfigPath(v string) Option { return func(o *Options) { o.ConfigurePath = v } }