Switch to Go 1.16 embed functionality (#42)
commit 8b9ecaaa2fe8b65e3a32317e2979387af39b5262 Author: Vic Demuzere <vic@demuzere.be> Date: Tue Aug 24 15:14:38 2021 +0200 Switch to Go 1.6 embed functionality This means the go-bindata compile-time dependency is no longer needed. closes #42 Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
f1751aff86
commit
71fa3b7590
5 changed files with 10 additions and 63118 deletions
1
Makefile
1
Makefile
|
@ -13,7 +13,6 @@ default: generate
|
||||||
generate: download_libs
|
generate: download_libs
|
||||||
docker run --rm -ti -v $(CURDIR):$(CURDIR) -w $(CURDIR)/src node:10-alpine \
|
docker run --rm -ti -v $(CURDIR):$(CURDIR) -w $(CURDIR)/src node:10-alpine \
|
||||||
sh -exc "npx npm@lts ci && npx npm@lts run build && chown -R $(shell id -u) ../frontend node_modules"
|
sh -exc "npx npm@lts ci && npx npm@lts run build && chown -R $(shell id -u) ../frontend node_modules"
|
||||||
go generate
|
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
curl -sSLo golang.sh https://raw.githubusercontent.com/Luzifer/github-publish/master/golang.sh
|
curl -sSLo golang.sh https://raw.githubusercontent.com/Luzifer/github-publish/master/golang.sh
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -1,6 +1,6 @@
|
||||||
module github.com/Luzifer/ots
|
module github.com/Luzifer/ots
|
||||||
|
|
||||||
go 1.13
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Luzifer/go_helpers/v2 v2.10.0
|
github.com/Luzifer/go_helpers/v2 v2.10.0
|
||||||
|
|
8
main.go
8
main.go
|
@ -1,8 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
//go:generate go-bindata -pkg $GOPACKAGE -o assets.go -modtime 1 -md5checksum ./frontend/...
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -29,6 +28,9 @@ var (
|
||||||
version = "dev"
|
version = "dev"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed frontend/*
|
||||||
|
var assets embed.FS
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if err := rconfig.ParseAndValidate(&cfg); err != nil {
|
if err := rconfig.ParseAndValidate(&cfg); err != nil {
|
||||||
log.Fatalf("Error parsing CLI arguments: %s", err)
|
log.Fatalf("Error parsing CLI arguments: %s", err)
|
||||||
|
@ -75,7 +77,7 @@ func assetDelivery(res http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ext := assetName[dot:]
|
ext := assetName[dot:]
|
||||||
assetData, err := Asset(path.Join("frontend", assetName))
|
assetData, err := assets.ReadFile(path.Join("frontend", assetName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(res, "404 not found", http.StatusNotFound)
|
http.Error(res, "404 not found", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
|
|
|
@ -12,7 +12,10 @@ var tplFuncs = template.FuncMap{
|
||||||
}
|
}
|
||||||
|
|
||||||
func assetSRIHash(assetName string) string {
|
func assetSRIHash(assetName string) string {
|
||||||
data := MustAsset(path.Join("frontend", assetName))
|
data, err := assets.ReadFile(path.Join("frontend", assetName))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
h := sha512.New384()
|
h := sha512.New384()
|
||||||
h.Write(data)
|
h.Write(data)
|
||||||
|
|
Loading…
Reference in a new issue