Compare commits

...
5 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
Pierre Dubouilh 557b3fd50d fix dockerbuild 2020-10-25 15:48:22 +01:00
7 changed files with 57 additions and 17 deletions
+1
View File
@@ -5,6 +5,7 @@ gossa-linux-arm64
gossa-mac gossa-mac
gossa-windows.exe gossa-windows.exe
gossa_test.go gossa_test.go
build-all
.vscode .vscode
test-fixture/* test-fixture/*
+20 -12
View File
@@ -1,8 +1,11 @@
FLAGS := -ldflags "-s -w"
NOCGO := CGO_ENABLED=0
build: 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 ${NOCGO} go build ${FLAGS} -o gossa
rm gossa.go rm gossa.go
install: install:
@@ -19,18 +22,22 @@ run-extra:
test: test:
make build make build
-rm gossa_test.go rm -rf gossa_test.go
-@cd test-fixture && ln -s ../support . -@cd test-fixture && ln -s ../support .; true
cp src/gossa_test.go . cp src/gossa_test.go .
-@killall gossa
make run & -@killall gossa; true
-make run &
go test -run TestNormal go test -run TestNormal
killall gossa killall gossa
make run-extra & -make run-extra &
go test -run TestExtra go test -run TestExtra
killall gossa killall gossa
make run-ro & -make run-ro &
go test -run TestRo go test -run TestRo
killall gossa killall gossa
watch: watch:
@@ -48,11 +55,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 ${NOCGO} GOOS=linux GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-linux64
env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o gossa-linux-arm ${NOCGO} GOOS=linux GOARCH=arm go build ${FLAGS} -o build-all/gossa-linux-arm
env CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o gossa-linux-arm64 ${NOCGO} GOOS=linux GOARCH=arm64 go build ${FLAGS} -o build-all/gossa-linux-arm64
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o gossa-mac ${NOCGO} GOOS=darwin GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-mac
env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o gossa-windows.exe ${NOCGO} GOOS=windows GOARCH=amd64 go build ${FLAGS} -o build-all/gossa-windows.exe
rm gossa.go rm gossa.go
clean: clean:
@@ -64,3 +71,4 @@ clean:
-rm gossa-linux-arm64 -rm gossa-linux-arm64
-rm gossa-mac -rm gossa-mac
-rm gossa-windows.exe -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 * ⌨️ keyboard navigation
* 🥂 fast golang static server * 🥂 fast golang static server
* 🔒 easy/secure multi account setup, read-only mode * 🔒 easy/secure multi account setup, read-only mode
* ✨ PWA enabled
### build ### build
built blobs are available on the [release page](https://github.com/pldubouilh/gossa/releases) - or simply `make build` this repo. 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 ( 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)
} }