implement Save

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-05-09 18:47:50 +03:00
parent 1658fc9a93
commit b18033c417
6 changed files with 23 additions and 11 deletions

View File

@@ -63,7 +63,7 @@ func (c *serviceConfig) Load(ctx context.Context) error {
rsp, err := c.client.Load(ctx, &pb.LoadRequest{Service: c.service})
if err != nil && !c.opts.AllowFail {
return fmt.Errorf("failed to load error config: %w", err)
return fmt.Errorf("failed to load config: %w", err)
}
src, err := rutil.Zero(c.opts.Struct)
@@ -93,6 +93,17 @@ func (c *serviceConfig) Save(ctx context.Context) error {
}
}
buf, err := c.opts.Codec.Marshal(c.opts.Struct)
if err != nil && c.opts.AllowFail {
return nil
} else if err != nil {
return err
}
if _, err = c.client.Save(ctx, &pb.SaveRequest{Service: c.service, Config: buf}); err != nil && !c.opts.AllowFail {
return fmt.Errorf("failed to save config: %w", err)
}
for _, fn := range c.opts.AfterSave {
if err := fn(ctx, c); err != nil && !c.opts.AllowFail {
return err