Merge pull request #90 from infosiftr/sha256sum

Add `sha256sum` template function
This commit is contained in:
Tianon Gravi 2024-01-22 09:43:56 -08:00 committed by GitHub
commit bc4c23b04c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 0 deletions

View File

@ -1,6 +1,8 @@
package templatelib
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"os"
@ -135,4 +137,10 @@ var FuncMap = template.FuncMap{
return unsetVal
}
}),
// {{- sha256sum "hello world" -}}
"sha256sum": func(input string) string {
hash := sha256.Sum256([]byte(input))
return hex.EncodeToString(hash[:])
},
}