mirror of
https://github.com/pldubouilh/gossa.git
synced 2026-09-02 23:27:39 -04:00
add compression on page
and strip build blobs
This commit is contained in:
committed by
Pierre Dubouilh
parent
557b3fd50d
commit
e490853baa
@@ -2,7 +2,7 @@ build:
|
|||||||
cp src/gossa.go gossa.go
|
cp src/gossa.go gossa.go
|
||||||
make -C gossa-ui/
|
make -C gossa-ui/
|
||||||
go vet && go fmt
|
go vet && go fmt
|
||||||
CGO_ENABLED=0 go build -o gossa
|
CGO_ENABLED=0 go build -ldflags "-s -w" -o gossa
|
||||||
rm gossa.go
|
rm gossa.go
|
||||||
|
|
||||||
install:
|
install:
|
||||||
@@ -48,11 +48,11 @@ watch-test:
|
|||||||
build-all:
|
build-all:
|
||||||
cp src/gossa.go gossa.go
|
cp src/gossa.go gossa.go
|
||||||
make -C gossa-ui/
|
make -C gossa-ui/
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o gossa-linux64
|
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o gossa-linux64
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o gossa-linux-arm
|
env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags "-s -w" -o gossa-linux-arm
|
||||||
env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o gossa-linux-arm64
|
env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w" -o gossa-linux-arm64
|
||||||
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o gossa-mac
|
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w" -o gossa-mac
|
||||||
env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o gossa-windows.exe
|
env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -o gossa-windows.exe
|
||||||
rm gossa.go
|
rm gossa.go
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@@ -64,3 +64,4 @@ clean:
|
|||||||
-rm gossa-linux-arm64
|
-rm gossa-linux-arm64
|
||||||
-rm gossa-mac
|
-rm gossa-mac
|
||||||
-rm gossa-windows.exe
|
-rm gossa-windows.exe
|
||||||
|
|
||||||
|
|||||||
+12
-3
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
|
"compress/gzip"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
@@ -80,7 +81,7 @@ func humanize(bytes int64) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func replyList(w http.ResponseWriter, fullPath string, path string) {
|
func replyList(w http.ResponseWriter, r *http.Request, fullPath string, path string) {
|
||||||
_files, err := ioutil.ReadDir(fullPath)
|
_files, err := ioutil.ReadDir(fullPath)
|
||||||
check(err)
|
check(err)
|
||||||
sort.Slice(_files, func(i, j int) bool { return strings.ToLower(_files[i].Name()) < strings.ToLower(_files[j].Name()) })
|
sort.Slice(_files, func(i, j int) bool { return strings.ToLower(_files[i].Name()) < strings.ToLower(_files[j].Name()) })
|
||||||
@@ -116,7 +117,15 @@ func replyList(w http.ResponseWriter, fullPath string, path string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
page.Execute(w, p)
|
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
|
||||||
|
w.Header().Set("Content-Type", "text/html")
|
||||||
|
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)
|
||||||
|
} else {
|
||||||
|
page.Execute(w, p)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func doContent(w http.ResponseWriter, r *http.Request) {
|
func doContent(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -132,7 +141,7 @@ func doContent(w http.ResponseWriter, r *http.Request) {
|
|||||||
check(errStat)
|
check(errStat)
|
||||||
|
|
||||||
if stat.IsDir() {
|
if stat.IsDir() {
|
||||||
replyList(w, fullPath, path)
|
replyList(w, r, fullPath, path)
|
||||||
} else {
|
} else {
|
||||||
fs.ServeHTTP(w, r)
|
fs.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user