Internal asset generation

This commit is contained in:
paul 2019-12-14 07:27:15 +01:00
parent 911ac38d05
commit cf455ba7d9
2 changed files with 25 additions and 16 deletions

22
assets/assets_generate.go Normal file
View file

@ -0,0 +1,22 @@
// +build ignore
package main
import (
"log"
"bitmask.me/skeleton/assets"
"github.com/shurcooL/vfsgen"
)
func main() {
err := vfsgen.Generate(assets.Assets, vfsgen.Options{
PackageName: "assets",
BuildTags: "!dev",
VariableName: "Assets",
Filename: "./assets/assets_vfsdata.go",
})
if err != nil {
log.Fatalln(err)
}
}

View file

@ -3,8 +3,6 @@
package assets
import (
"go/build"
"log"
"net/http"
"github.com/shurcooL/httpfs/union"
@ -15,18 +13,7 @@ import (
// the root folder defined in the map should be prepended
// to the file path
var Assets = union.New(map[string]http.FileSystem{
"/migrations": http.Dir(importPathToDir("bitmask.me/skeleton/assets/migrations")),
"/templates": http.Dir(importPathToDir("bitmask.me/skeleton/assets/templates")),
"/static": http.Dir(importPathToDir("bitmask.me/skeleton/assets/static")),
"/migrations": http.Dir("./assets/migrations"),
"/templates": http.Dir("./assets/templates"),
"/static": http.Dir("./assets/static"),
})
// importPathToDir is a helper function that resolves the absolute path of
// modules, so they can be used both in dev mode (`-tags="dev"`) or with a
// generated static asset file (`go generate`).
func importPathToDir(importPath string) string {
p, err := build.Import(importPath, "", build.FindOnly)
if err != nil {
log.Fatalln(err)
}
return p.Dir
}