Merge pull request 'allow to override Struct on Save' (#126) from fix into v3

Reviewed-on: #126
This commit is contained in:
Василий Толстов 2023-03-15 00:03:55 +03:00
commit 352de16fae
1 changed files with 6 additions and 1 deletions

View File

@ -157,13 +157,18 @@ func (c *consulConfig) Save(ctx context.Context, opts ...config.SaveOption) erro
path := c.path
dst := c.opts.Struct
if options.Struct != nil {
dst = options.Struct
}
if options.Context != nil {
if v, ok := options.Context.Value(pathKey{}).(string); ok && v != "" {
path = v
}
}
buf, err := c.opts.Codec.Marshal(c.opts.Struct)
buf, err := c.opts.Codec.Marshal(dst)
if err == nil {
_, err = c.cli.KV().Put(&api.KVPair{Key: path, Value: buf}, nil)
}