diff options
Diffstat (limited to 'pkg/utils.go')
-rw-r--r-- | pkg/utils.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/pkg/utils.go b/pkg/utils.go new file mode 100644 index 0000000..f62d1c3 --- /dev/null +++ b/pkg/utils.go @@ -0,0 +1,27 @@ +package gonf + +import ( + "crypto/sha256" +) + +var builtinTemplateFunctions = map[string]any{ + //"encodeURIQueryParameter": url.QueryEscape, + "var": getVariable, +} + +func FilterSlice[T any](slice *[]T, predicate func(T) bool) { + i := 0 + for _, element := range *slice { + if predicate(element) { // if the element matches the predicate function + (*slice)[i] = element // then we keep it in the slice + i++ + } // otherwise the element will get overwritten + } + *slice = (*slice)[:i] // or truncated out of the slice +} + +func sha256sum(contents []byte) []byte { + h := sha256.New() + h.Write(contents) + return h.Sum(nil) +} |