Skip to content

Commit

Permalink
[core] Add json.Sort function to workflow template context
Browse files Browse the repository at this point in the history
  • Loading branch information
teo authored and knopers8 committed Dec 12, 2024
1 parent 27baac2 commit 6f64bf3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions configuration/template/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ func MakeUtilFuncMap(varStack map[string]string) map[string]interface{} {
out = string(bytes)
return
},
"Sort": func(in interface{}) (out interface{}) {
switch inSlice := in.(type) {
case []interface{}:
stringSlice := make([]string, len(inSlice))
for idx, item := range inSlice {
stringSlice[idx] = fmt.Sprintf("%v", item)
}
slices.Sort(stringSlice)
out = stringSlice
default:
out = in
}
return
},
}
jsonMap["Deserialize"] = jsonMap["Unmarshal"]
jsonMap["Serialize"] = jsonMap["Marshal"]
Expand Down

0 comments on commit 6f64bf3

Please sign in to comment.