update for latest micro

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-09-30 01:28:03 +03:00
parent e0cbe28c8f
commit a4002ae8eb
3 changed files with 19 additions and 49 deletions

View File

@ -82,38 +82,23 @@ func (c *consulConfig) Init(opts ...config.Option) error {
}
func (c *consulConfig) Load(ctx context.Context, opts ...config.LoadOption) error {
for _, fn := range c.opts.BeforeLoad {
if err := fn(ctx, c); err != nil {
c.opts.Logger.Errorf(c.opts.Context, "consul load err: %v", err)
if !c.opts.AllowFail {
if err := config.DefaultBeforeLoad(ctx, c); err != nil {
return err
}
}
}
pair, _, err := c.cli.KV().Get(c.path, nil)
if err != nil {
c.opts.Logger.Errorf(c.opts.Context, "consul load path %s err: %v", c.path, err)
if !c.opts.AllowFail {
return fmt.Errorf("consul path %s load error: %v", c.path, err)
}
err = fmt.Errorf("consul path %s load error: %w", c.path, err)
} else if pair == nil {
c.opts.Logger.Errorf(c.opts.Context, "consul load path %s not found", c.path)
if !c.opts.AllowFail {
return fmt.Errorf("consul path %s not found", c.path)
}
err = fmt.Errorf("consul path %s load error: not found", c.path)
}
if err != nil || pair == nil {
for _, fn := range c.opts.AfterLoad {
if err := fn(ctx, c); err != nil {
c.opts.Logger.Errorf(c.opts.Context, "consul load err: %v", err)
if err != nil {
c.opts.Logger.Error(c.opts.Context, err)
if !c.opts.AllowFail {
return err
}
}
}
return nil
return config.DefaultAfterLoad(ctx, c)
}
options := config.NewLoadOptions(opts...)
@ -145,27 +130,17 @@ func (c *consulConfig) Load(ctx context.Context, opts ...config.LoadOption) erro
}
}
for _, fn := range c.opts.AfterLoad {
if err := fn(ctx, c); err != nil {
c.opts.Logger.Errorf(c.opts.Context, "consul load err: %v", err)
if !c.opts.AllowFail {
if err := config.DefaultAfterLoad(ctx, c); err != nil {
return err
}
}
}
return nil
}
func (c *consulConfig) Save(ctx context.Context, opts ...config.SaveOption) error {
for _, fn := range c.opts.BeforeSave {
if err := fn(ctx, c); err != nil {
c.opts.Logger.Errorf(c.opts.Context, "consul save err: %v", err)
if !c.opts.AllowFail {
if err := config.DefaultBeforeSave(ctx, c); err != nil {
return err
}
}
}
buf, err := c.opts.Codec.Marshal(c.opts.Struct)
if err == nil {
@ -173,20 +148,15 @@ func (c *consulConfig) Save(ctx context.Context, opts ...config.SaveOption) erro
}
if err != nil {
c.opts.Logger.Errorf(c.opts.Context, "consul path %s save err: %v", c.path, err)
c.opts.Logger.Errorf(c.opts.Context, "consul path %s save error: %v", c.path, err)
if !c.opts.AllowFail {
return fmt.Errorf("consul path %s save error: %v", c.path, err)
}
}
for _, fn := range c.opts.AfterSave {
if err := fn(ctx, c); err != nil {
c.opts.Logger.Errorf(c.opts.Context, "consul save err: %v", err)
if !c.opts.AllowFail {
if err := config.DefaultAfterSave(ctx, c); err != nil {
return err
}
}
}
return nil
}

2
go.mod
View File

@ -16,5 +16,5 @@ require (
github.com/mitchellh/mapstructure v1.4.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/unistack-org/micro/v3 v3.7.5
github.com/unistack-org/micro/v3 v3.7.6
)

4
go.sum
View File

@ -164,8 +164,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/unistack-org/micro-proto v0.0.9 h1:KrWLS4FUX7UAWNAilQf70uad6ZPf/0EudeddCXllRVc=
github.com/unistack-org/micro-proto v0.0.9/go.mod h1:Cckwmzd89gvS7ThxzZp9kQR/EOdksFQcsTAtDDyKwrg=
github.com/unistack-org/micro/v3 v3.7.5 h1:ucNsxi6mApYRpYHbiNKqTLY3V8oGQDfnHn+AbtnFBdo=
github.com/unistack-org/micro/v3 v3.7.5/go.mod h1:Ke/8WJlNZi4ZYwL9HcsANAbQ66/HocTBEZM+od99/mM=
github.com/unistack-org/micro/v3 v3.7.6 h1:cobNkaicZR+8nbDWRUmX3/CSLh6ZNSytK2zWth4s4IM=
github.com/unistack-org/micro/v3 v3.7.6/go.mod h1:Ke/8WJlNZi4ZYwL9HcsANAbQ66/HocTBEZM+od99/mM=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=