Skip to content

Commit c9fc738

Browse files
committed
nil-check at value normilization
1 parent ebfd405 commit c9fc738

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

utils/templating/templating.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"regexp"
88
"strings"
99
"text/template"
10-
11-
"github.com/codeshelldev/secured-signal-api/utils/logger"
1210
)
1311

1412
func normalize(value any) string {
@@ -30,7 +28,11 @@ func normalize(value any) string {
3028
}
3129

3230
func normalizeJSON(value any) string {
33-
switch value.(type) {
31+
if value == nil {
32+
return ""
33+
}
34+
35+
switch value.(type) {
3436
case []any, []string, map[string]any, int, float64, bool:
3537
object, _ := json.Marshal(value)
3638

@@ -71,7 +73,6 @@ func RenderJSONTemplate(name string, data map[string]any, variables any) (map[st
7173
jsonBytes, err := json.Marshal(data)
7274

7375
if err != nil {
74-
logger.Dev("72"+err.Error())
7576
return nil, err
7677
}
7778

@@ -91,15 +92,13 @@ func RenderJSONTemplate(name string, data map[string]any, variables any) (map[st
9192
jsonStr, err := ParseTemplate(templt, tmplStr, variables)
9293

9394
if err != nil {
94-
logger.Dev("92:"+err.Error())
9595
return nil, err
9696
}
9797

9898
// Remove the Quotes around "<<[item1,item2]>>"
9999
re, err = regexp.Compile(`"<<(.*?)>>"`)
100100

101101
if err != nil {
102-
logger.Dev("100:"+err.Error())
103102
return nil, err
104103
}
105104

@@ -108,7 +107,6 @@ func RenderJSONTemplate(name string, data map[string]any, variables any) (map[st
108107
err = json.Unmarshal([]byte(jsonStr), &data)
109108

110109
if err != nil {
111-
logger.Dev("109:"+err.Error())
112110
return nil, err
113111
}
114112

0 commit comments

Comments
 (0)