Compare commits

..
4 Commits
Author SHA1 Message Date
Pierre Dubouilh df85a1c5a2 test snap 2021-11-12 15:45:28 +01:00
Pierre Dubouilh e2aa4f149e shuffle makefile & add empty go.mod
go 1.16 requires go.mod in git folders now apparently
2021-04-17 16:06:57 +02:00
Pierre Dubouilh 8a7a542b22 bump ui 2021-04-17 16:06:57 +02:00
Pierre Dubouilh e490853baa add compression on page
and strip build blobs
2021-04-17 16:06:57 +02:00
7 changed files with 57 additions and 17 deletions
+2 -1
View File
@@ -5,6 +5,7 @@ gossa-linux-arm64
gossa-mac
gossa-windows.exe
gossa_test.go
build-all
.vscode
test-fixture/*
@@ -39,4 +40,4 @@ test-fixture/*/*
!test-fixture/fancy-path
!test-fixture/fancy-path/*
!test-fixture/ext/*
!test-fixture/ext
!test-fixture/ext
+20 -12
View File
@@ -1,8 +1,11 @@
FLAGS := -ldflags "-s -w"
NOCGO := CGO_ENABLED=0
build:
cp src/gossa.go gossa.go
make -C gossa-ui/
go vet && go fmt
CGO_ENABLED=0 go build -o gossa
${NOCGO} go build ${FLAGS} -o gossa
rm gossa.go
install:
@@ -19,18 +22,22 @@ run-extra:
test:
make build
-rm gossa_test.go
-@cd test-fixture && ln -s ../support .
rm -rf gossa_test.go
-@cd test-fixture && ln -s ../support .; true
cp src/gossa_test.go .
-@killall gossa
make run &
-@killall gossa; true
-make run &
go test -run TestNormal
killall gossa
make run-extra &
-make run-extra &
go test -run TestExtra
killall gossa
make run-ro &
-make run-ro &
go test -run TestRo
killall gossa
watch:
@@ -48,11 +55,11 @@ watch-test:
build-all:
cp src/gossa.go gossa.go
make -C gossa-ui/
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o gossa-linux64
env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o gossa-linux-arm
env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o gossa-linux-arm64
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o gossa-mac
env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o gossa-windows.exe
${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:
@@ -64,3 +71,4 @@ clean:
-rm gossa-linux-arm64
-rm gossa-mac
-rm gossa-windows.exe
+3
View File
@@ -0,0 +1,3 @@
module github.com/pldubouilh/gossa
go 1.16
+1
View File
@@ -22,6 +22,7 @@ a [simple UI](https://github.com/pldubouilh/gossa-ui) comes as default, featurin
* ⌨️ keyboard navigation
* 🥂 fast golang static server
* 🔒 easy/secure multi account setup, read-only mode
* ✨ PWA enabled
### build
built blobs are available on the [release page](https://github.com/pldubouilh/gossa/releases) - or simply `make build` this repo.
+18
View File
@@ -0,0 +1,18 @@
name: gossa
version: git
summary: a fast and simple webserver for your files.
description: |
a fast and simple webserver for your files, that's dependency-free and easy to review.
confinement: strict
base: core18
parts:
gossa:
plugin: go
go-importpath: github.com/pldubouilh/gossa
source: .
source-type: git
build-packages:
- gcc
apps:
gossa:
command: gossa
+12 -3
View File
@@ -2,6 +2,7 @@ package main
import (
"archive/zip"
"compress/gzip"
"encoding/json"
"errors"
"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)
check(err)
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) {
@@ -132,7 +141,7 @@ func doContent(w http.ResponseWriter, r *http.Request) {
check(errStat)
if stat.IsDir() {
replyList(w, fullPath, path)
replyList(w, r, fullPath, path)
} else {
fs.ServeHTTP(w, r)
}