Skip to content

Commit cc3d6c2

Browse files
committed
[core] Add json.Sort function to workflow template context
1 parent de4d866 commit cc3d6c2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

configuration/template/stack.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,20 @@ func MakeUtilFuncMap(varStack map[string]string) map[string]interface{} {
263263
out = string(bytes)
264264
return
265265
},
266+
"Sort": func(in interface{}) (out interface{}) {
267+
switch inSlice := in.(type) {
268+
case []interface{}:
269+
stringSlice := make([]string, len(inSlice))
270+
for idx, item := range inSlice {
271+
stringSlice[idx] = fmt.Sprintf("%v", item)
272+
}
273+
slices.Sort(stringSlice)
274+
out = stringSlice
275+
default:
276+
out = in
277+
}
278+
return
279+
},
266280
}
267281
jsonMap["Deserialize"] = jsonMap["Unmarshal"]
268282
jsonMap["Serialize"] = jsonMap["Marshal"]

0 commit comments

Comments
 (0)