Skip to content

Commit

Permalink
Add Unmarshal to config.Transformer to expose them in -show
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
KristianLyng committed Jun 4, 2024
1 parent 66ea46a commit d24ea53
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d24ea53

Please sign in to comment.