summaryrefslogtreecommitdiff
path: root/pkg/utils.go
diff options
context:
space:
mode:
authorJulien Dessaux2024-03-07 00:54:35 +0100
committerJulien Dessaux2024-03-07 01:02:23 +0100
commit560becfd32dd7355547938f3c6229060dd395aab (patch)
tree42329f4e47c64349ae8a0205f867632ac52bcdc6 /pkg/utils.go
parentfeat(stdlib): began adding systemd services support (diff)
downloadgonf-560becfd32dd7355547938f3c6229060dd395aab.tar.gz
gonf-560becfd32dd7355547938f3c6229060dd395aab.tar.bz2
gonf-560becfd32dd7355547938f3c6229060dd395aab.zip
chore(repo): renamed gonf subfolder to something more traditional in go land
Diffstat (limited to 'pkg/utils.go')
-rw-r--r--pkg/utils.go27
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)
+}