Knut Ahlers
71fa3b7590
commit 8b9ecaaa2fe8b65e3a32317e2979387af39b5262 Author: Vic Demuzere <vic@demuzere.be> Date: Tue Aug 24 15:14:38 2021 +0200 Switch to Go 1.6 embed functionality This means the go-bindata compile-time dependency is no longer needed. closes #42 Signed-off-by: Knut Ahlers <knut@ahlers.me>
25 lines
410 B
Go
25 lines
410 B
Go
package main
|
|
|
|
import (
|
|
"crypto/sha512"
|
|
"encoding/base64"
|
|
"path"
|
|
"text/template"
|
|
)
|
|
|
|
var tplFuncs = template.FuncMap{
|
|
"SRIHash": assetSRIHash,
|
|
}
|
|
|
|
func assetSRIHash(assetName string) string {
|
|
data, err := assets.ReadFile(path.Join("frontend", assetName))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
h := sha512.New384()
|
|
h.Write(data)
|
|
sum := h.Sum(nil)
|
|
|
|
return "sha384-" + base64.StdEncoding.EncodeToString(sum)
|
|
}
|