From d24ea53b4e3ab04036b612754e3a3068de920a0d Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Tue, 4 Jun 2024 12:42:56 +0200 Subject: [PATCH] Add Unmarshal to config.Transformer to expose them in -show Fixes #308 This is a weird oversight, but also an excellent example of where you'd use generics if you were to re-do this today. --- config/parse.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/config/parse.go b/config/parse.go index a38aa613..49695cb2 100644 --- a/config/parse.go +++ b/config/parse.go @@ -97,6 +97,21 @@ type Config struct { Transformers map[string]*Transformer } +// MarshalJSON marshals Transformer config. See MarshalJSON for receiver - same +// same. +func (t *Transformer) MarshalJSON() ([]byte, error) { + nest, err := json.Marshal(t.Transformer) + if err != nil { + return nil, err + } + var merged map[string]interface{} + if err := json.Unmarshal(nest, &merged); err != nil { + return nil, err + } + merged["type"] = t.Type + return json.Marshal(merged) +} + // UnmarshalJSON picks up the type of the Receiver, instantiates a copy of // that receiver, then unmarshals the remaining configuration onto that. func (t *Transformer) UnmarshalJSON(b []byte) error {