mirror of
https://github.com/pldubouilh/gossa.git
synced 2026-09-05 16:47:39 -04:00
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:
committed by
Pierre Dubouilh
co-authored by
Victor
parent
e2aa4f149e
commit
a2754c616d
@@ -7,10 +7,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- name: Set up Go 1.13
|
- name: Set up Go 1.17.3
|
||||||
uses: actions/setup-go@v1
|
uses: actions/setup-go@v1
|
||||||
with:
|
with:
|
||||||
go-version: 1.13
|
go-version: 1.17.3
|
||||||
id: go
|
id: go
|
||||||
|
|
||||||
- name: Check out code into the Go module directory
|
- name: Check out code into the Go module directory
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ gossa-linux-arm
|
|||||||
gossa-linux-arm64
|
gossa-linux-arm64
|
||||||
gossa-mac
|
gossa-mac
|
||||||
gossa-windows.exe
|
gossa-windows.exe
|
||||||
gossa_test.go
|
|
||||||
build-all
|
build-all
|
||||||
|
|
||||||
.vscode
|
.vscode
|
||||||
|
|||||||
@@ -2,11 +2,8 @@ FLAGS := -ldflags "-s -w"
|
|||||||
NOCGO := CGO_ENABLED=0
|
NOCGO := CGO_ENABLED=0
|
||||||
|
|
||||||
build:
|
build:
|
||||||
cp src/gossa.go gossa.go
|
|
||||||
make -C gossa-ui/
|
|
||||||
go vet && go fmt
|
go vet && go fmt
|
||||||
${NOCGO} go build ${FLAGS} -o gossa
|
${NOCGO} go build ${FLAGS} -o gossa
|
||||||
rm gossa.go
|
|
||||||
|
|
||||||
install:
|
install:
|
||||||
sudo cp gossa /usr/local/bin
|
sudo cp gossa /usr/local/bin
|
||||||
@@ -22,9 +19,7 @@ run-extra:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
make build
|
make build
|
||||||
rm -rf gossa_test.go
|
|
||||||
-@cd test-fixture && ln -s ../support .; true
|
-@cd test-fixture && ln -s ../support .; true
|
||||||
cp src/gossa_test.go .
|
|
||||||
|
|
||||||
-@killall gossa; true
|
-@killall gossa; true
|
||||||
-make run &
|
-make run &
|
||||||
@@ -41,30 +36,25 @@ test:
|
|||||||
killall gossa
|
killall gossa
|
||||||
|
|
||||||
watch:
|
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:
|
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:
|
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:
|
watch-test:
|
||||||
ls src/* gossa-ui/* | entr -rc make test
|
ls gossa.go gossa_test.go gossa-ui/* | entr -rc make test
|
||||||
|
|
||||||
build-all:
|
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=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=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=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=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
|
${NOCGO} GOOS=windows GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-windows.exe
|
||||||
rm gossa.go
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm gossa.go
|
|
||||||
-rm gossa_test.go
|
|
||||||
-rm gossa
|
-rm gossa
|
||||||
-rm gossa-linux64
|
-rm gossa-linux64
|
||||||
-rm gossa-linux-arm
|
-rm gossa-linux-arm
|
||||||
|
|||||||
+1
-1
Submodule gossa-ui updated: a057f08e1d...5ec0a804c9
+23
-3
@@ -3,6 +3,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
_ "embed"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
@@ -31,7 +33,19 @@ var ro = flag.Bool("ro", false, "read only mode (no upload, rename, move, etc...
|
|||||||
var initPath = "."
|
var initPath = "."
|
||||||
|
|
||||||
var fs http.Handler
|
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 {
|
type rowTemplate struct {
|
||||||
Name string
|
Name string
|
||||||
@@ -122,9 +136,9 @@ func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path str
|
|||||||
w.Header().Add("Content-Encoding", "gzip")
|
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)
|
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()
|
defer gz.Close()
|
||||||
page.Execute(gz, p)
|
templateParsed.Execute(gz, p)
|
||||||
} else {
|
} else {
|
||||||
page.Execute(w, p)
|
templateParsed.Execute(w, p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,6 +246,12 @@ func main() {
|
|||||||
initPath, err = filepath.Abs(initPath)
|
initPath, err = filepath.Abs(initPath)
|
||||||
check(err)
|
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 {
|
if !*ro {
|
||||||
http.HandleFunc(*extraPath+"rpc", rpc)
|
http.HandleFunc(*extraPath+"rpc", rpc)
|
||||||
http.HandleFunc(*extraPath+"post", upload)
|
http.HandleFunc(*extraPath+"post", upload)
|
||||||
Reference in New Issue
Block a user