update for latest micro
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
e0cbe28c8f
commit
a4002ae8eb
62
consul.go
62
consul.go
@ -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 {
|
||||
return err
|
||||
}
|
||||
}
|
||||
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 !c.opts.AllowFail {
|
||||
return 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,26 +130,16 @@ 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 {
|
||||
return err
|
||||
}
|
||||
}
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := config.DefaultBeforeSave(ctx, c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf, err := c.opts.Codec.Marshal(c.opts.Struct)
|
||||
@ -173,19 +148,14 @@ 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 {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := config.DefaultAfterSave(ctx, c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
2
go.mod
2
go.mod
@ -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
4
go.sum
@ -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=
|
||||
|
Loading…
x
Reference in New Issue
Block a user