Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
c90ee27de1 | |||
5f9029c496 |
17
flag.go
17
flag.go
@ -1,4 +1,4 @@
|
||||
package flag // import "go.unistack.org/micro-config-flag/v4"
|
||||
package flag
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -10,9 +10,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.unistack.org/micro/v4/config"
|
||||
"go.unistack.org/micro/v4/options"
|
||||
rutil "go.unistack.org/micro/v4/util/reflect"
|
||||
"go.unistack.org/micro/v3/config"
|
||||
rutil "go.unistack.org/micro/v3/util/reflect"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -40,7 +39,7 @@ func (c *flagConfig) Options() config.Options {
|
||||
return c.opts
|
||||
}
|
||||
|
||||
func (c *flagConfig) Init(opts ...options.Option) error {
|
||||
func (c *flagConfig) Init(opts ...config.Option) error {
|
||||
for _, o := range opts {
|
||||
o(&c.opts)
|
||||
}
|
||||
@ -156,7 +155,7 @@ func (c *flagConfig) Init(opts ...options.Option) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *flagConfig) Load(ctx context.Context, opts ...options.Option) error {
|
||||
func (c *flagConfig) Load(ctx context.Context, opts ...config.LoadOption) error {
|
||||
if c.opts.SkipLoad != nil && c.opts.SkipLoad(ctx, c) {
|
||||
return nil
|
||||
}
|
||||
@ -178,7 +177,7 @@ func (c *flagConfig) Load(ctx context.Context, opts ...options.Option) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *flagConfig) Save(ctx context.Context, opts ...options.Option) error {
|
||||
func (c *flagConfig) Save(ctx context.Context, opts ...config.SaveOption) error {
|
||||
if c.opts.SkipSave != nil && c.opts.SkipSave(ctx, c) {
|
||||
return nil
|
||||
}
|
||||
@ -202,7 +201,7 @@ func (c *flagConfig) Name() string {
|
||||
return c.opts.Name
|
||||
}
|
||||
|
||||
func (c *flagConfig) Watch(ctx context.Context, opts ...options.Option) (config.Watcher, error) {
|
||||
func (c *flagConfig) Watch(ctx context.Context, opts ...config.WatchOption) (config.Watcher, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
@ -317,7 +316,7 @@ func (c *flagConfig) configure() {
|
||||
c.name = flagSetName
|
||||
}
|
||||
|
||||
func NewConfig(opts ...options.Option) config.Config {
|
||||
func NewConfig(opts ...config.Option) config.Config {
|
||||
options := config.NewOptions(opts...)
|
||||
if len(options.StructTag) == 0 {
|
||||
options.StructTag = DefaultStructTag
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.unistack.org/micro/v4/config"
|
||||
"go.unistack.org/micro/v3/config"
|
||||
)
|
||||
|
||||
func TestLoad(t *testing.T) {
|
||||
|
4
go.mod
4
go.mod
@ -1,8 +1,8 @@
|
||||
module go.unistack.org/micro-config-flag/v4
|
||||
module go.unistack.org/micro-config-flag/v3
|
||||
|
||||
go 1.18
|
||||
|
||||
require go.unistack.org/micro/v4 v4.0.17
|
||||
require go.unistack.org/micro/v3 v3.10.44
|
||||
|
||||
require (
|
||||
dario.cat/mergo v1.0.0 // indirect
|
||||
|
4
go.sum
4
go.sum
@ -2,8 +2,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
|
||||
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
go.unistack.org/micro/v4 v4.0.17 h1:mF7uM+J4ILdG+1fcwzKYCwDlxhdbF/e1WnGzKKLnIXc=
|
||||
go.unistack.org/micro/v4 v4.0.17/go.mod h1:ZDgU9931vm2l7X6RN/6UuwRIVp24GRdmQ7dKmegArk4=
|
||||
go.unistack.org/micro/v3 v3.10.44 h1:Vgyy9BrJOSdFvo29/klrgIBE/Nme9E8udPAljos34o0=
|
||||
go.unistack.org/micro/v3 v3.10.44/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg=
|
||||
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=
|
||||
|
35
options.go
35
options.go
@ -3,61 +3,62 @@ package flag
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"go.unistack.org/micro/v4/options"
|
||||
"go.unistack.org/micro/v3/config"
|
||||
)
|
||||
|
||||
type sliceDelimKey struct{}
|
||||
|
||||
// SliceDelim set the slice delimeter
|
||||
func SliceDelim(s string) options.Option {
|
||||
return options.ContextOption(sliceDelimKey{}, s)
|
||||
func SliceDelim(s string) config.Option {
|
||||
return config.SetOption(sliceDelimKey{}, s)
|
||||
}
|
||||
|
||||
type mapDelimKey struct{}
|
||||
|
||||
// MapDelim set the map delimeter
|
||||
func MapDelim(s string) options.Option {
|
||||
return options.ContextOption(mapDelimKey{}, s)
|
||||
func MapDelim(s string) config.Option {
|
||||
return config.SetOption(mapDelimKey{}, s)
|
||||
}
|
||||
|
||||
type timeFormatKey struct{}
|
||||
|
||||
// TimeFormat set the time format
|
||||
func TimeFormat(s string) options.Option {
|
||||
return options.ContextOption(timeFormatKey{}, s)
|
||||
func TimeFormat(s string) config.Option {
|
||||
return config.SetOption(timeFormatKey{}, s)
|
||||
}
|
||||
|
||||
type flagSetKey struct{}
|
||||
|
||||
// FlagSet set flag set name
|
||||
func FlagSet(f *flag.FlagSet) options.Option {
|
||||
return options.ContextOption(flagSetKey{}, f)
|
||||
func FlagSet(f *flag.FlagSet) config.Option {
|
||||
return config.SetOption(flagSetKey{}, f)
|
||||
}
|
||||
|
||||
type flagSetNameKey struct{}
|
||||
|
||||
// FlagSetName set flag set name
|
||||
func FlagSetName(n string) options.Option {
|
||||
return options.ContextOption(flagSetNameKey{}, n)
|
||||
func FlagSetName(n string) config.Option {
|
||||
return config.SetOption(flagSetNameKey{}, n)
|
||||
}
|
||||
|
||||
type flagSetErrorHandlingKey struct{}
|
||||
|
||||
// FlagErrorHandling set flag set error handling
|
||||
func FlagErrorHandling(eh flag.ErrorHandling) options.Option {
|
||||
return options.ContextOption(flagSetErrorHandlingKey{}, eh)
|
||||
func FlagErrorHandling(eh flag.ErrorHandling) config.Option {
|
||||
return config.SetOption(flagSetErrorHandlingKey{}, eh)
|
||||
}
|
||||
|
||||
type flagSetUsageKey struct{}
|
||||
|
||||
// FlagUsage set flag set usage func
|
||||
func FlagUsage(fn func()) options.Option {
|
||||
return options.ContextOption(flagSetUsageKey{}, fn)
|
||||
func FlagUsage(fn func()) config.Option {
|
||||
return config.SetOption(flagSetUsageKey{}, fn)
|
||||
}
|
||||
|
||||
|
||||
type flagEnvKey struct{}
|
||||
|
||||
// FlagEnv set flag set usage func
|
||||
func FlagEnv(n string) options.Option {
|
||||
return options.ContextOption(flagEnvKey{}, n)
|
||||
func FlagEnv(n string) config.Option {
|
||||
return config.SetOption(flagEnvKey{}, n)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user