diff --git a/flag.go b/flag.go index 887b7e0..9e7967a 100644 --- a/flag.go +++ b/flag.go @@ -11,6 +11,7 @@ import ( "time" "go.unistack.org/micro/v4/config" + "go.unistack.org/micro/v4/options" rutil "go.unistack.org/micro/v4/util/reflect" ) @@ -39,7 +40,7 @@ func (c *flagConfig) Options() config.Options { return c.opts } -func (c *flagConfig) Init(opts ...config.Option) error { +func (c *flagConfig) Init(opts ...options.Option) error { for _, o := range opts { o(&c.opts) } @@ -155,7 +156,7 @@ func (c *flagConfig) Init(opts ...config.Option) error { return nil } -func (c *flagConfig) Load(ctx context.Context, opts ...config.LoadOption) error { +func (c *flagConfig) Load(ctx context.Context, opts ...options.Option) error { options := config.NewLoadOptions(opts...) _ = options @@ -173,7 +174,7 @@ func (c *flagConfig) Load(ctx context.Context, opts ...config.LoadOption) error return nil } -func (c *flagConfig) Save(ctx context.Context, opts ...config.SaveOption) error { +func (c *flagConfig) Save(ctx context.Context, opts ...options.Option) error { if err := config.DefaultBeforeSave(ctx, c); err != nil && !c.opts.AllowFail { return err } @@ -193,7 +194,7 @@ func (c *flagConfig) Name() string { return c.opts.Name } -func (c *flagConfig) Watch(ctx context.Context, opts ...config.WatchOption) (config.Watcher, error) { +func (c *flagConfig) Watch(ctx context.Context, opts ...options.Option) (config.Watcher, error) { return nil, fmt.Errorf("not implemented") } @@ -308,7 +309,7 @@ func (c *flagConfig) configure() { c.name = flagSetName } -func NewConfig(opts ...config.Option) config.Config { +func NewConfig(opts ...options.Option) config.Config { options := config.NewOptions(opts...) if len(options.StructTag) == 0 { options.StructTag = DefaultStructTag diff --git a/go.mod b/go.mod index e22e9e6..9cef3cb 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,9 @@ module go.unistack.org/micro-config-flag/v3 go 1.18 -require go.unistack.org/micro/v4 v4.0.1 +require go.unistack.org/micro/v4 v4.0.5 -require github.com/imdario/mergo v0.3.14 // indirect +require ( + github.com/google/uuid v1.3.0 // indirect + github.com/imdario/mergo v0.3.16 // indirect +) diff --git a/go.sum b/go.sum index 6ac6217..abbf684 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,13 @@ -github.com/imdario/mergo v0.3.14 h1:fOqeC1+nCuuk6PKQdg9YmosXX7Y7mHX6R/0ZldI9iHo= -github.com/imdario/mergo v0.3.14/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM= +github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= +github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= +github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= go.unistack.org/micro/v4 v4.0.1 h1:xo1IxbVfgh8i0eY0VeYa3cbb13u5n/Mxnp3FOgWD4Jo= go.unistack.org/micro/v4 v4.0.1/go.mod h1:p/J5UcSJjfHsWGT31uKoghQ5rUQZzQJBAFy+Z4+ZVMs= +go.unistack.org/micro/v4 v4.0.5 h1:uacmV8yHjCOtVfECc4w1tgp6bd3bBWrZa8X4iQLk48g= +go.unistack.org/micro/v4 v4.0.5/go.mod h1:bVEYTlPi0EsdgZZt311bIroDg9ict7ky3C87dSCCAGk= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/options.go b/options.go index 0dbb35d..9c5f6b8 100644 --- a/options.go +++ b/options.go @@ -3,61 +3,61 @@ package flag import ( "flag" - "go.unistack.org/micro/v4/config" + "go.unistack.org/micro/v4/options" ) type sliceDelimKey struct{} // SliceDelim set the slice delimeter -func SliceDelim(s string) config.Option { - return config.SetOption(sliceDelimKey{}, s) +func SliceDelim(s string) options.Option { + return options.ContextOption(sliceDelimKey{}, s) } type mapDelimKey struct{} // MapDelim set the map delimeter -func MapDelim(s string) config.Option { - return config.SetOption(mapDelimKey{}, s) +func MapDelim(s string) options.Option { + return options.ContextOption(mapDelimKey{}, s) } type timeFormatKey struct{} // TimeFormat set the time format -func TimeFormat(s string) config.Option { - return config.SetOption(timeFormatKey{}, s) +func TimeFormat(s string) options.Option { + return options.ContextOption(timeFormatKey{}, s) } type flagSetKey struct{} // FlagSet set flag set name -func FlagSet(f *flag.FlagSet) config.Option { - return config.SetOption(flagSetKey{}, f) +func FlagSet(f *flag.FlagSet) options.Option { + return options.ContextOption(flagSetKey{}, f) } type flagSetNameKey struct{} // FlagSetName set flag set name -func FlagSetName(n string) config.Option { - return config.SetOption(flagSetNameKey{}, n) +func FlagSetName(n string) options.Option { + return options.ContextOption(flagSetNameKey{}, n) } type flagSetErrorHandlingKey struct{} // FlagErrorHandling set flag set error handling -func FlagErrorHandling(eh flag.ErrorHandling) config.Option { - return config.SetOption(flagSetErrorHandlingKey{}, eh) +func FlagErrorHandling(eh flag.ErrorHandling) options.Option { + return options.ContextOption(flagSetErrorHandlingKey{}, eh) } type flagSetUsageKey struct{} // FlagUsage set flag set usage func -func FlagUsage(fn func()) config.Option { - return config.SetOption(flagSetUsageKey{}, fn) +func FlagUsage(fn func()) options.Option { + return options.ContextOption(flagSetUsageKey{}, fn) } type flagEnvKey struct{} // FlagEnv set flag set usage func -func FlagEnv(n string) config.Option { - return config.SetOption(flagEnvKey{}, n) +func FlagEnv(n string) options.Option { + return options.ContextOption(flagEnvKey{}, n) }