Switch to Go 1.6 embed functionality

This means the go-bindata compile-time dependency is no longer needed.
This commit is contained in:
Vic Demuzere 2021-08-24 15:14:38 +02:00
parent 26233c635c
commit 4dcc2fb266
No known key found for this signature in database
GPG Key ID: 5B9EA1616690CF94
5 changed files with 10 additions and 63118 deletions

View File

@ -13,7 +13,6 @@ default: generate
generate: download_libs
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"
go generate
publish:
curl -sSLo golang.sh https://raw.githubusercontent.com/Luzifer/github-publish/master/golang.sh

63112
assets.go

File diff suppressed because it is too large Load Diff

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/Luzifer/ots
go 1.13
go 1.16
require (
github.com/Luzifer/go_helpers/v2 v2.10.0

View File

@ -1,8 +1,7 @@
package main
//go:generate go-bindata -pkg $GOPACKAGE -o assets.go -modtime 1 -md5checksum ./frontend/...
import (
"embed"
"fmt"
"mime"
"net/http"
@ -29,6 +28,9 @@ var (
version = "dev"
)
//go:embed frontend/*
var assets embed.FS
func init() {
if err := rconfig.ParseAndValidate(&cfg); err != nil {
log.Fatalf("Error parsing CLI arguments: %s", err)
@ -74,7 +76,7 @@ func assetDelivery(res http.ResponseWriter, r *http.Request) {
}
ext := assetName[strings.LastIndex(assetName, "."):]
assetData, err := Asset(path.Join("frontend", assetName))
assetData, err := assets.ReadFile(path.Join("frontend", assetName))
if err != nil {
http.Error(res, "404 not found", http.StatusNotFound)
return

View File

@ -12,7 +12,10 @@ var tplFuncs = template.FuncMap{
}
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.Write(data)