update for micro changes

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-12-19 23:25:40 +03:00
parent c65c85b08b
commit 2b8c1d6c4a
3 changed files with 8 additions and 6 deletions

10
env.go
View File

@ -31,19 +31,19 @@ func (c *envConfig) Init(opts ...config.Option) error {
func (c *envConfig) Load(ctx context.Context) error { func (c *envConfig) Load(ctx context.Context) error {
for _, fn := range c.opts.BeforeLoad { for _, fn := range c.opts.BeforeLoad {
if err := fn(ctx, c); err != nil { if err := fn(ctx, c); err != nil && !c.opts.AllowFail {
return err return err
} }
} }
valueOf := reflect.ValueOf(c.opts.Struct) valueOf := reflect.ValueOf(c.opts.Struct)
if err := c.fillValues(ctx, valueOf); err != nil { if err := c.fillValues(ctx, valueOf); err != nil && !c.opts.AllowFail {
return err return err
} }
for _, fn := range c.opts.AfterLoad { for _, fn := range c.opts.AfterLoad {
if err := fn(ctx, c); err != nil { if err := fn(ctx, c); err != nil && !c.opts.AllowFail {
return err return err
} }
} }
@ -232,13 +232,13 @@ func (c *envConfig) fillValues(ctx context.Context, valueOf reflect.Value) error
func (c *envConfig) Save(ctx context.Context) error { func (c *envConfig) Save(ctx context.Context) error {
for _, fn := range c.opts.BeforeSave { for _, fn := range c.opts.BeforeSave {
if err := fn(ctx, c); err != nil { if err := fn(ctx, c); err != nil && !c.opts.AllowFail {
return err return err
} }
} }
for _, fn := range c.opts.AfterSave { for _, fn := range c.opts.AfterSave {
if err := fn(ctx, c); err != nil { if err := fn(ctx, c); err != nil && !c.opts.AllowFail {
return err return err
} }
} }

2
go.mod
View File

@ -2,4 +2,4 @@ module github.com/unistack-org/micro-config-env
go 1.15 go 1.15
require github.com/unistack-org/micro/v3 v3.0.2-0.20201213101738-2dcd30b21c0f require github.com/unistack-org/micro/v3 v3.0.2-0.20201219202205-150e8ad698bb

2
go.sum
View File

@ -237,6 +237,8 @@ github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4
github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g=
github.com/unistack-org/micro/v3 v3.0.2-0.20201213101738-2dcd30b21c0f h1:VTnea0NAgE0LXQNBpiemP/O6G0Uns6sl5KkyeAKodEU= github.com/unistack-org/micro/v3 v3.0.2-0.20201213101738-2dcd30b21c0f h1:VTnea0NAgE0LXQNBpiemP/O6G0Uns6sl5KkyeAKodEU=
github.com/unistack-org/micro/v3 v3.0.2-0.20201213101738-2dcd30b21c0f/go.mod h1:0DgOy4OdJxQCDER8YSKitZugd2+1bddrRSNfeooTHDc= github.com/unistack-org/micro/v3 v3.0.2-0.20201213101738-2dcd30b21c0f/go.mod h1:0DgOy4OdJxQCDER8YSKitZugd2+1bddrRSNfeooTHDc=
github.com/unistack-org/micro/v3 v3.0.2-0.20201219202205-150e8ad698bb h1:cJGF8j30idReDyjRCvEJN5waWCh/AKuiKEqLA8OLMlY=
github.com/unistack-org/micro/v3 v3.0.2-0.20201219202205-150e8ad698bb/go.mod h1:0DgOy4OdJxQCDER8YSKitZugd2+1bddrRSNfeooTHDc=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA= github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=