From cf455ba7d9e15bd4dda1c4ca57ec445b680a4928 Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 14 Dec 2019 07:27:15 +0100 Subject: [PATCH] Internal asset generation --- assets/assets_generate.go | 22 ++++++++++++++++++++++ assets/dev.go | 19 +++---------------- 2 files changed, 25 insertions(+), 16 deletions(-) create mode 100644 assets/assets_generate.go diff --git a/assets/assets_generate.go b/assets/assets_generate.go new file mode 100644 index 0000000..6dbf068 --- /dev/null +++ b/assets/assets_generate.go @@ -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) + } +} \ No newline at end of file diff --git a/assets/dev.go b/assets/dev.go index b1e2f54..9c9ac58 100644 --- a/assets/dev.go +++ b/assets/dev.go @@ -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 -}