12 Commits

Author SHA1 Message Date
9326172c1a Merge pull request 'Update workflows' (#80) from atolstikhin/micro-config-flag:master into master
All checks were successful
test / test (push) Successful in 11m42s
Reviewed-on: #80
2024-12-12 12:11:45 +03:00
62396f149d Merge branch 'master' into master
Some checks failed
dependabot-automerge / automerge (pull_request) Has been skipped
automerge / automerge (pull_request) Failing after 17s
autoapprove / autoapprove (pull_request) Failing after 31s
lint / lint (pull_request) Successful in 1m5s
test / test (pull_request) Successful in 11m58s
2024-12-12 11:42:08 +03:00
ec3ae6b934 fix lint
Some checks failed
build / lint (push) Successful in 46s
build / test (push) Failing after 48s
codeql / analyze (go) (push) Failing after 1m23s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-12-12 11:39:15 +03:00
Aleksandr Tolstikhin
922f68f784 Update workflows
Some checks failed
automerge / automerge (pull_request) Has been skipped
dependabot-automerge / automerge (pull_request) Has been skipped
autoapprove / autoapprove (pull_request) Successful in 7s
lint / lint (pull_request) Has been cancelled
test / test (pull_request) Has been cancelled
2024-12-12 08:17:45 +07:00
e712519f44 update deps
Some checks failed
build / test (push) Failing after 1m12s
codeql / analyze (go) (push) Failing after 1m52s
build / lint (push) Successful in 9m16s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-03-06 18:01:04 +03:00
a8d5f21394 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:01:49 +03:00
5fef84faa0 Merge pull request 'update to latest micro' (#77) from micro-v4 into master
Some checks failed
build / test (push) Failing after 1m29s
build / lint (push) Failing after 2m37s
codeql / analyze (go) (push) Failing after 3m4s
Reviewed-on: #77
2023-07-30 00:38:40 +03:00
600608bda5 update to latest micro
Some checks failed
autoapprove / autoapprove (pull_request) Failing after 1m27s
automerge / automerge (pull_request) Failing after 4s
codeql / analyze (go) (pull_request) Failing after 4m52s
dependabot-automerge / automerge (pull_request) Has been skipped
prbuild / test (pull_request) Failing after 1m44s
prbuild / lint (pull_request) Failing after 2m42s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-07-30 00:38:15 +03:00
728f1ca453 Изменил(а) на 'go.mod'
Some checks failed
build / test (push) Failing after 8s
build / lint (push) Failing after 6s
codeql / analyze (go) (push) Failing after 7s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-07-09 15:43:26 +03:00
c325b0a760 Merge pull request 'move to micro v4' (#76) from v4 into master
Some checks failed
build / test (push) Failing after 7s
build / lint (push) Failing after 4s
codeql / analyze (go) (push) Failing after 5s
Reviewed-on: #76
2023-05-05 19:58:39 +03:00
05cb25c2e1 move to micro v4
Some checks failed
prbuild / test (pull_request) Failing after 5s
prbuild / lint (pull_request) Failing after 5s
codeql / analyze (go) (pull_request) Failing after 5s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-05-05 19:57:12 +03:00
bc599cddb3 Merge branch 'v3' 2023-05-05 19:56:08 +03:00
5 changed files with 40 additions and 50 deletions

23
flag.go
View File

@@ -1,4 +1,4 @@
package flag
package flag // import "go.unistack.org/micro-config-flag/v4"
import (
"context"
@@ -10,8 +10,9 @@ import (
"strings"
"time"
"go.unistack.org/micro/v3/config"
rutil "go.unistack.org/micro/v3/util/reflect"
"go.unistack.org/micro/v4/config"
"go.unistack.org/micro/v4/options"
rutil "go.unistack.org/micro/v4/util/reflect"
)
var (
@@ -39,9 +40,13 @@ 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 {
var err error
for _, o := range opts {
o(&c.opts)
if err = o(&c.opts); err != nil {
return err
}
}
if err := config.DefaultBeforeInit(c.opts.Context, c); err != nil && !c.opts.AllowFail {
@@ -155,7 +160,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 {
if c.opts.SkipLoad != nil && c.opts.SkipLoad(ctx, c) {
return nil
}
@@ -177,7 +182,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 c.opts.SkipSave != nil && c.opts.SkipSave(ctx, c) {
return nil
}
@@ -201,7 +206,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")
}
@@ -316,7 +321,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

View File

@@ -7,7 +7,7 @@ import (
"testing"
"time"
"go.unistack.org/micro/v3/config"
"go.unistack.org/micro/v4/config"
)
func TestLoad(t *testing.T) {

14
go.mod
View File

@@ -1,16 +1,10 @@
module go.unistack.org/micro-config-flag/v3
module go.unistack.org/micro-config-flag/v4
go 1.22
go 1.18
toolchain go1.23.1
require go.unistack.org/micro/v3 v3.11.14
require go.unistack.org/micro/v4 v4.0.17
require (
dario.cat/mergo v1.0.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
dario.cat/mergo v1.0.0 // indirect
github.com/google/uuid v1.6.0 // indirect
go.unistack.org/micro-proto/v3 v3.4.1 // indirect
google.golang.org/protobuf v1.35.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

16
go.sum
View File

@@ -1,17 +1,9 @@
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
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-proto/v3 v3.4.1 h1:UTjLSRz2YZuaHk9iSlVqqsA50JQNAEK2ZFboGqtEa9Q=
go.unistack.org/micro-proto/v3 v3.4.1/go.mod h1:okx/cnOhzuCX0ggl/vToatbCupi0O44diiiLLsZ93Zo=
go.unistack.org/micro/v3 v3.10.97 h1:8l7fv+i06/PjPrBBhRC/ZQkWGIOuHPg3jJN0vktYE78=
go.unistack.org/micro/v3 v3.10.97/go.mod h1:YzMldzHN9Ei+zy5t/Psu7RUWDZwUfrNYiStSQtTz90g=
go.unistack.org/micro/v3 v3.11.14 h1:3e9T30Ih9cvqZTCD8inG1qsBWRk4x5ZinWuTiDFM4CE=
go.unistack.org/micro/v3 v3.11.14/go.mod h1:k++F5Ej4LIy3XnOW/oj3P7B97wp2t9yLSlqtUzMpatM=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
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=
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=

View File

@@ -3,62 +3,61 @@ package flag
import (
"flag"
"go.unistack.org/micro/v3/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)
}