From 365f97d092b61a798fc18ff83304319e7766e5b5 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 25 Mar 2024 13:27:51 +0100 Subject: [PATCH] Flatten(): type-check input only once --- pkg/flatten/flatten.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/flatten/flatten.go b/pkg/flatten/flatten.go index 7ce8c6a91..127cbfbde 100644 --- a/pkg/flatten/flatten.go +++ b/pkg/flatten/flatten.go @@ -31,12 +31,10 @@ func Flatten(value interface{}, prefix string) map[string]types.String { for i, v := range value { flatten(key+"["+strconv.Itoa(i)+"]", v) } + case nil: + flattened[key] = types.MakeString("null") default: - val := "null" - if value != nil { - val = fmt.Sprintf("%v", value) - } - flattened[key] = types.MakeString(val) + flattened[key] = types.MakeString(fmt.Sprintf("%v", value)) } }