Internal asset generation
This commit is contained in:
parent
911ac38d05
commit
cf455ba7d9
2 changed files with 25 additions and 16 deletions
22
assets/assets_generate.go
Normal file
22
assets/assets_generate.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,8 +3,6 @@
|
||||||
package assets
|
package assets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go/build"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/shurcooL/httpfs/union"
|
"github.com/shurcooL/httpfs/union"
|
||||||
|
@ -15,18 +13,7 @@ import (
|
||||||
// the root folder defined in the map should be prepended
|
// the root folder defined in the map should be prepended
|
||||||
// to the file path
|
// to the file path
|
||||||
var Assets = union.New(map[string]http.FileSystem{
|
var Assets = union.New(map[string]http.FileSystem{
|
||||||
"/migrations": http.Dir(importPathToDir("bitmask.me/skeleton/assets/migrations")),
|
"/migrations": http.Dir("./assets/migrations"),
|
||||||
"/templates": http.Dir(importPathToDir("bitmask.me/skeleton/assets/templates")),
|
"/templates": http.Dir("./assets/templates"),
|
||||||
"/static": http.Dir(importPathToDir("bitmask.me/skeleton/assets/static")),
|
"/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
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue