use go static assets embedder

shift to use new static go assets embedded

Co-authored-by:     Victor <ViRb3@users.noreply.github.com>
This commit is contained in:
Pierre Dubouilh
2021-12-22 14:29:46 +01:00
committed by Pierre Dubouilh
co-authored by Victor
parent e2aa4f149e
commit a2754c616d
6 changed files with 30 additions and 21 deletions
+2 -2
View File
@@ -7,10 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.13
- name: Set up Go 1.17.3
uses: actions/setup-go@v1
with:
go-version: 1.13
go-version: 1.17.3
id: go
- name: Check out code into the Go module directory
-1
View File
@@ -4,7 +4,6 @@ gossa-linux-arm
gossa-linux-arm64
gossa-mac
gossa-windows.exe
gossa_test.go
build-all
.vscode
+4 -14
View File
@@ -2,11 +2,8 @@ FLAGS := -ldflags "-s -w"
NOCGO := CGO_ENABLED=0
build:
cp src/gossa.go gossa.go
make -C gossa-ui/
go vet && go fmt
${NOCGO} go build ${FLAGS} -o gossa
rm gossa.go
install:
sudo cp gossa /usr/local/bin
@@ -22,9 +19,7 @@ run-extra:
test:
make build
rm -rf gossa_test.go
-@cd test-fixture && ln -s ../support .; true
cp src/gossa_test.go .
-@killall gossa; true
-make run &
@@ -41,30 +36,25 @@ test:
killall gossa
watch:
ls src/* gossa-ui/* | entr -rc make build run
ls gossa.go gossa_test.go gossa-ui/* | entr -rc make build run
watch-extra:
ls src/* gossa-ui/* | entr -rc make build run-extra
ls gossa.go gossa_test.go gossa-ui/* | entr -rc make build run-extra
watch-ro:
ls src/* gossa-ui/* | entr -rc make build run-ro
ls gossa.go gossa_test.go gossa-ui/* | entr -rc make build run-ro
watch-test:
ls src/* gossa-ui/* | entr -rc make test
ls gossa.go gossa_test.go gossa-ui/* | entr -rc make test
build-all:
cp src/gossa.go gossa.go
make -C gossa-ui/
${NOCGO} GOOS=linux GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-linux64
${NOCGO} GOOS=linux GOARCH=arm go build ${FLAGS} -o build-all/gossa-linux-arm
${NOCGO} GOOS=linux GOARCH=arm64 go build ${FLAGS} -o build-all/gossa-linux-arm64
${NOCGO} GOOS=darwin GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-mac
${NOCGO} GOOS=windows GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-windows.exe
rm gossa.go
clean:
-rm gossa.go
-rm gossa_test.go
-rm gossa
-rm gossa-linux64
-rm gossa-linux-arm
+23 -3
View File
@@ -3,6 +3,8 @@ package main
import (
"archive/zip"
"compress/gzip"
_ "embed"
"encoding/base64"
"encoding/json"
"errors"
"flag"
@@ -31,7 +33,19 @@ var ro = flag.Bool("ro", false, "read only mode (no upload, rename, move, etc...
var initPath = "."
var fs http.Handler
var page, _ = template.New("pageTemplate").Parse(`template_will_be_here`)
//go:embed gossa-ui/ui.tmpl
var templateStr string
var templateParsed *template.Template
//go:embed gossa-ui/script.js
var scriptJs string
//go:embed gossa-ui/style.css
var styleCss string
//go:embed gossa-ui/favicon.svg
var faviconSvg []byte
type rowTemplate struct {
Name string
@@ -122,9 +136,9 @@ func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path str
w.Header().Add("Content-Encoding", "gzip")
gz, _ := gzip.NewWriterLevel(w, gzip.BestSpeed) // BestSpeed is much faster than Default on a very unscientific local test, and only ~30% larger (compression remains still very effective, ~6x)
defer gz.Close()
page.Execute(gz, p)
templateParsed.Execute(gz, p)
} else {
page.Execute(w, p)
templateParsed.Execute(w, p)
}
}
@@ -232,6 +246,12 @@ func main() {
initPath, err = filepath.Abs(initPath)
check(err)
templateStr = strings.Replace(templateStr, "css_will_be_here", styleCss, 1)
templateStr = strings.Replace(templateStr, "js_will_be_here", scriptJs, 1)
templateStr = strings.Replace(templateStr, "favicon_will_be_here", base64.StdEncoding.EncodeToString(faviconSvg), 2)
templateParsed, err = template.New("").Parse(templateStr)
check(err)
if !*ro {
http.HandleFunc(*extraPath+"rpc", rpc)
http.HandleFunc(*extraPath+"post", upload)
View File