commit 1c670e02d93922b38d35a4b521078ef5e5efd75b
parent 5ec9353fa413b3df30762c9c35ea4077d12bbe9f
Author: Vetle Haflan <vetle@haflan.dev>
Date: Sun, 12 Apr 2020 07:22:41 +0200
Finish the production tag build
Now it's possible to run
go build -tags PRODUCTION ./cmd/sermoni
to embed the website in code, assuming the generated html.go file
exists in internal/http
Diffstat:
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/internal/http/html_dev.go b/internal/http/html_dev.go
@@ -4,15 +4,12 @@ package http
import "io/ioutil"
-func check(err error) {
+// In production mode, the website is embedded in (generated) code
+// In dev mode it's more useful to read the html file on every request
+func getWebsite() []byte {
+ htmlData, err := ioutil.ReadFile("ui/dist/index.html")
if err != nil {
panic(err)
}
-}
-
-// In dev mode, the file is read from the generated html file
-func getWebsite() []byte {
- htmlData, err := ioutil.ReadFile("ui/dist/index.html")
- check(err)
return htmlData
}
diff --git a/ui/generate.sh b/ui/generate.sh
@@ -23,9 +23,12 @@ cp $INDEX_HTML $HTML_GO
sed -i 's/`/`\+"`"\+`/g' $HTML_GO
cat <<EOF > $HTML_GO
// +build PRODUCTION
+
package http
-var websiteHTML = []byte(\`
+func getWebsite() []byte {
+ return []byte(\`
$(cat $HTML_GO)
-\`)
+ \`)
+}
EOF