summaryrefslogtreecommitdiff
path: root/pkg/utils.go
blob: f62d1c3485239a70fdd9266f7f74a9372ea49664 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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)
}