From 4030b1d131f2d80d2df0a75fb0f1f8081f44e7ad Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 15 Mar 2023 00:03:33 +0300 Subject: [PATCH] allow to override Struct on Save Signed-off-by: Vasiliy Tolstov --- consul.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/consul.go b/consul.go index 23e7593..464103e 100644 --- a/consul.go +++ b/consul.go @@ -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) }