7 Commits

Author SHA1 Message Date
a349fdda8e move to micro v4
All checks were successful
test / test (push) Successful in 2m41s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2025-03-07 12:48:31 +03:00
3293df4ede Merge pull request 'Update workflows' (#81) from atolstikhin/micro-config-flag:v3 into v3
All checks were successful
test / test (push) Successful in 11m49s
Reviewed-on: #81
2024-12-12 11:55:36 +03:00
9c8a232d76 Merge branch 'v3' into v3
Some checks failed
dependabot-automerge / automerge (pull_request) Has been skipped
lint / lint (pull_request) Successful in 1m11s
test / test (pull_request) Successful in 12m21s
autoapprove / autoapprove (pull_request) Failing after 13m20s
automerge / automerge (pull_request) Failing after 13m18s
2024-12-12 11:40:23 +03:00
9ec19b3806 fix lint
Some checks failed
build / test (push) Failing after 18s
build / lint (push) Successful in 16s
codeql / analyze (go) (push) Failing after 1m16s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-12-12 11:38:45 +03:00
Aleksandr Tolstikhin
f40f518bf0 Update workflows
Some checks failed
automerge / automerge (pull_request) Has been skipped
autoapprove / autoapprove (pull_request) Successful in 6s
dependabot-automerge / automerge (pull_request) Has been skipped
lint / lint (pull_request) Failing after 23s
test / test (pull_request) Has been cancelled
2024-12-12 08:19:52 +07:00
c90ee27de1 update deps
Some checks failed
build / test (push) Failing after 1m24s
build / lint (push) Successful in 9m35s
codeql / analyze (go) (push) Failing after 11m17s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-03-06 17:35:31 +03:00
5f9029c496 fixup conditions
Some checks failed
build / test (push) Has been cancelled
build / lint (push) Has been cancelled
codeql / analyze (go) (push) Has been cancelled
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-01-15 02:02:50 +03:00
4 changed files with 64 additions and 36 deletions

19
flag.go
View File

@@ -1,4 +1,4 @@
package flag // import "go.unistack.org/micro-config-flag/v4" package flag
import ( import (
"context" "context"
@@ -11,7 +11,6 @@ import (
"time" "time"
"go.unistack.org/micro/v4/config" "go.unistack.org/micro/v4/config"
"go.unistack.org/micro/v4/options"
rutil "go.unistack.org/micro/v4/util/reflect" rutil "go.unistack.org/micro/v4/util/reflect"
) )
@@ -40,13 +39,9 @@ func (c *flagConfig) Options() config.Options {
return c.opts return c.opts
} }
func (c *flagConfig) Init(opts ...options.Option) error { func (c *flagConfig) Init(opts ...config.Option) error {
var err error
for _, o := range opts { for _, o := range opts {
if err = o(&c.opts); err != nil { o(&c.opts)
return err
}
} }
if err := config.DefaultBeforeInit(c.opts.Context, c); err != nil && !c.opts.AllowFail { if err := config.DefaultBeforeInit(c.opts.Context, c); err != nil && !c.opts.AllowFail {
@@ -160,7 +155,7 @@ func (c *flagConfig) Init(opts ...options.Option) error {
return nil 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) { if c.opts.SkipLoad != nil && c.opts.SkipLoad(ctx, c) {
return nil return nil
} }
@@ -182,7 +177,7 @@ func (c *flagConfig) Load(ctx context.Context, opts ...options.Option) error {
return nil 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) { if c.opts.SkipSave != nil && c.opts.SkipSave(ctx, c) {
return nil return nil
} }
@@ -206,7 +201,7 @@ func (c *flagConfig) Name() string {
return c.opts.Name 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") return nil, fmt.Errorf("not implemented")
} }
@@ -321,7 +316,7 @@ func (c *flagConfig) configure() {
c.name = flagSetName c.name = flagSetName
} }
func NewConfig(opts ...options.Option) config.Config { func NewConfig(opts ...config.Option) config.Config {
options := config.NewOptions(opts...) options := config.NewOptions(opts...)
if len(options.StructTag) == 0 { if len(options.StructTag) == 0 {
options.StructTag = DefaultStructTag options.StructTag = DefaultStructTag

15
go.mod
View File

@@ -1,10 +1,19 @@
module go.unistack.org/micro-config-flag/v4 module go.unistack.org/micro-config-flag/v4
go 1.18 go 1.22.0
require go.unistack.org/micro/v4 v4.0.17 toolchain go1.24.1
require go.unistack.org/micro/v4 v4.1.3
require ( require (
dario.cat/mergo v1.0.0 // indirect dario.cat/mergo v1.0.1 // indirect
github.com/ash3in/uuidv8 v1.2.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.6.0 // indirect github.com/google/uuid v1.6.0 // indirect
github.com/matoous/go-nanoid v1.5.1 // indirect
github.com/spf13/cast v1.7.1 // indirect
go.unistack.org/micro-proto/v4 v4.1.0 // indirect
google.golang.org/protobuf v1.36.3 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

32
go.sum
View File

@@ -1,9 +1,33 @@
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/ash3in/uuidv8 v1.2.0 h1:2oogGdtCPwaVtyvPPGin4TfZLtOGE5F+W++E880G6SI=
github.com/ash3in/uuidv8 v1.2.0/go.mod h1:BnU0wJBxnzdEKmVg4xckBkD+VZuecTFTUP3M0dWgyY4=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= 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= 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= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
go.unistack.org/micro/v4 v4.0.17/go.mod h1:ZDgU9931vm2l7X6RN/6UuwRIVp24GRdmQ7dKmegArk4= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/matoous/go-nanoid v1.5.1 h1:aCjdvTyO9LLnTIi0fgdXhOPPvOHjpXN6Ik9DaNjIct4=
github.com/matoous/go-nanoid v1.5.1/go.mod h1:zyD2a71IubI24efhpvkJz+ZwfwagzgSO6UNiFsZKN7U=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
go.unistack.org/micro-proto/v4 v4.1.0 h1:qPwL2n/oqh9RE3RTTDgt28XK3QzV597VugQPaw9lKUk=
go.unistack.org/micro-proto/v4 v4.1.0/go.mod h1:ArmK7o+uFvxSY3dbJhKBBX4Pm1rhWdLEFf3LxBrMtec=
go.unistack.org/micro/v4 v4.1.3 h1:9QHiLHBTfPtfKyoY3HsLPNVSK0wlAAoMV+9saLz2iR4=
go.unistack.org/micro/v4 v4.1.3/go.mod h1:lr3oYED8Ay1vjK68QqRw30QOtdk/ffpZqMFDasOUhKw=
google.golang.org/protobuf v1.36.3 h1:82DV7MYdb8anAVi3qge1wSnMDrnKK7ebr+I0hHRN1BU=
google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -3,61 +3,61 @@ package flag
import ( import (
"flag" "flag"
"go.unistack.org/micro/v4/options" "go.unistack.org/micro/v4/config"
) )
type sliceDelimKey struct{} type sliceDelimKey struct{}
// SliceDelim set the slice delimeter // SliceDelim set the slice delimeter
func SliceDelim(s string) options.Option { func SliceDelim(s string) config.Option {
return options.ContextOption(sliceDelimKey{}, s) return config.SetOption(sliceDelimKey{}, s)
} }
type mapDelimKey struct{} type mapDelimKey struct{}
// MapDelim set the map delimeter // MapDelim set the map delimeter
func MapDelim(s string) options.Option { func MapDelim(s string) config.Option {
return options.ContextOption(mapDelimKey{}, s) return config.SetOption(mapDelimKey{}, s)
} }
type timeFormatKey struct{} type timeFormatKey struct{}
// TimeFormat set the time format // TimeFormat set the time format
func TimeFormat(s string) options.Option { func TimeFormat(s string) config.Option {
return options.ContextOption(timeFormatKey{}, s) return config.SetOption(timeFormatKey{}, s)
} }
type flagSetKey struct{} type flagSetKey struct{}
// FlagSet set flag set name // FlagSet set flag set name
func FlagSet(f *flag.FlagSet) options.Option { func FlagSet(f *flag.FlagSet) config.Option {
return options.ContextOption(flagSetKey{}, f) return config.SetOption(flagSetKey{}, f)
} }
type flagSetNameKey struct{} type flagSetNameKey struct{}
// FlagSetName set flag set name // FlagSetName set flag set name
func FlagSetName(n string) options.Option { func FlagSetName(n string) config.Option {
return options.ContextOption(flagSetNameKey{}, n) return config.SetOption(flagSetNameKey{}, n)
} }
type flagSetErrorHandlingKey struct{} type flagSetErrorHandlingKey struct{}
// FlagErrorHandling set flag set error handling // FlagErrorHandling set flag set error handling
func FlagErrorHandling(eh flag.ErrorHandling) options.Option { func FlagErrorHandling(eh flag.ErrorHandling) config.Option {
return options.ContextOption(flagSetErrorHandlingKey{}, eh) return config.SetOption(flagSetErrorHandlingKey{}, eh)
} }
type flagSetUsageKey struct{} type flagSetUsageKey struct{}
// FlagUsage set flag set usage func // FlagUsage set flag set usage func
func FlagUsage(fn func()) options.Option { func FlagUsage(fn func()) config.Option {
return options.ContextOption(flagSetUsageKey{}, fn) return config.SetOption(flagSetUsageKey{}, fn)
} }
type flagEnvKey struct{} type flagEnvKey struct{}
// FlagEnv set flag set usage func // FlagEnv set flag set usage func
func FlagEnv(n string) options.Option { func FlagEnv(n string) config.Option {
return options.ContextOption(flagEnvKey{}, n) return config.SetOption(flagEnvKey{}, n)
} }