gui: Enable proper asset caching (#4931)

This commit is contained in:
Audrius Butkevicius
2018-05-10 06:53:39 +01:00
committed by Jakob Borg
parent fb198a0645
commit e125f8b05b
3 changed files with 47 additions and 2 deletions

View File

@@ -19,10 +19,13 @@ import (
"path/filepath"
"strings"
"text/template"
"time"
)
var tpl = template.Must(template.New("assets").Parse(`package auto
const Generated int64 = {{.Generated}}
func Assets() map[string][]byte {
var assets = make(map[string][]byte, {{.Assets | len}})
{{range $asset := .Assets}}
@@ -75,7 +78,8 @@ func walkerFor(basePath string) filepath.WalkFunc {
}
type templateVars struct {
Assets []asset
Assets []asset
Generated int64
}
func main() {
@@ -84,7 +88,8 @@ func main() {
filepath.Walk(flag.Arg(0), walkerFor(flag.Arg(0)))
var buf bytes.Buffer
tpl.Execute(&buf, templateVars{
Assets: assets,
Assets: assets,
Generated: time.Now().Unix(),
})
bs, err := format.Source(buf.Bytes())
if err != nil {