2018-05-05 17:08:02 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/sha512"
|
|
|
|
"encoding/base64"
|
|
|
|
"path"
|
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
|
|
|
var tplFuncs = template.FuncMap{
|
|
|
|
"SRIHash": assetSRIHash,
|
|
|
|
}
|
|
|
|
|
|
|
|
func assetSRIHash(assetName string) string {
|
2021-09-06 10:37:52 +00:00
|
|
|
data, err := assets.ReadFile(path.Join("frontend", assetName))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2018-05-05 17:08:02 +00:00
|
|
|
|
|
|
|
h := sha512.New384()
|
|
|
|
h.Write(data)
|
|
|
|
sum := h.Sum(nil)
|
|
|
|
|
|
|
|
return "sha384-" + base64.StdEncoding.EncodeToString(sum)
|
|
|
|
}
|