Skip to content

Commit 46f1e84

Browse files
committed
fix?
1 parent d4f46c7 commit 46f1e84

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

tests/json_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
func TestJsonTemplating(t *testing.T) {
11-
variables := map[string]interface{}{
11+
variables := map[string]any{
1212
"array": []string{
1313
"item0",
1414
"item1",
@@ -28,17 +28,17 @@ func TestJsonTemplating(t *testing.T) {
2828
"key2": "{{.int}}"
2929
}`
3030

31-
data := utils.GetJson[map[string]interface{}](json)
31+
data := utils.GetJson[map[string]any](json)
3232

33-
expected := map[string]interface{}{
34-
"dict": map[string]interface{}{
33+
expected := map[string]any{
34+
"dict": map[string]any{
3535
"key": "val",
3636
},
37-
"dictArray": []interface{}{
38-
map[string]interface{}{"key": "val"},
39-
map[string]interface{}{"key": []interface{}{ "item0", "item1" }},
37+
"dictArray": []any{
38+
map[string]any{"key": "val"},
39+
map[string]any{"key": []any{ "item0", "item1" }},
4040
},
41-
"key1": []interface{}{ "item0", "item1" },
41+
"key1": []any{ "item0", "item1" },
4242
"key2": 4,
4343
}
4444

@@ -71,7 +71,7 @@ func TestJsonPath(t *testing.T) {
7171
"key": "val"
7272
}`
7373

74-
data := utils.GetJson[map[string]interface{}](json)
74+
data := utils.GetJson[map[string]any](json)
7575

7676
cases := []struct{
7777
key string

utils/templating/templating.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ func normalize(value any) string {
3030
}
3131

3232
func normalizeJSON(value any) string {
33-
jsonBytes, err := json.Marshal(value)
33+
switch value.(type) {
34+
case []any, []string, map[string]any, int, float64, bool:
35+
object, _ := json.Marshal(value)
3436

35-
if err != nil {
36-
return "INVALID:JSON"
37-
}
37+
return "<<" + string(object) + ">>"
3838

39-
return "<<" + string(jsonBytes) + ">>"
39+
default:
40+
return value.(string)
41+
}
4042
}
41-
4243
func ParseTemplate(templt *template.Template, tmplStr string, variables any) (string, error) {
4344
tmpl, err := templt.Parse(tmplStr)
4445

0 commit comments

Comments
 (0)