From 864dcd45a2be3e3a2b27ff22127d8169a52d92fa Mon Sep 17 00:00:00 2001 From: Gareth George Date: Mon, 5 May 2025 20:38:10 -0700 Subject: [PATCH] fix: use github.com/vearutop/statigz to embed webUI srcs and improve Accept-Encoding handling --- go.mod | 1 + go.sum | 2 ++ pkg/restic/restic.go | 10 +++++----- webui/webui.go | 4 +++- webui/webui_test.go | 4 ++-- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index b3d08d6a..1ca4556d 100644 --- a/go.mod +++ b/go.mod @@ -71,6 +71,7 @@ require ( github.com/prometheus/procfs v0.16.1 // indirect github.com/randall77/makefat v0.0.0-20210315173500-7ddd0e42c844 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect + github.com/vearutop/statigz v1.5.0 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect go.opentelemetry.io/otel v1.35.0 // indirect go.opentelemetry.io/otel/metric v1.35.0 // indirect diff --git a/go.sum b/go.sum index 59632056..f2b1d4e7 100644 --- a/go.sum +++ b/go.sum @@ -164,6 +164,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/vearutop/statigz v1.5.0 h1:FuWwZiT82yBw4xbWdWIawiP2XFTyEPhIo8upRxiKLqk= +github.com/vearutop/statigz v1.5.0/go.mod h1:oHmjFf3izfCO804Di1ZjB666P3fAlVzJEx2k6jNt/Gk= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.etcd.io/bbolt v1.3.11 h1:yGEzV1wPz2yVCLsD8ZAiGHhHVlczyC9d1rP43/VCRJ0= go.etcd.io/bbolt v1.3.11/go.mod h1:dksAq7YMXoljX0xu6VF5DMZGbhYYoLUalEiSySYAS4I= diff --git a/pkg/restic/restic.go b/pkg/restic/restic.go index af8cf9d0..9ff10074 100644 --- a/pkg/restic/restic.go +++ b/pkg/restic/restic.go @@ -53,12 +53,12 @@ func (r *Repo) commandWithContext(ctx context.Context, args []string, opts ...Ge resolveOpts(opt, r.opts) resolveOpts(opt, opts) - fullCmd := append([]string{r.cmd}, args...) - - if len(opt.prefixCmd) > 0 { - fullCmd = append(slices.Clone(opt.prefixCmd), fullCmd...) + var fullCmd []string + fullCmd = append(fullCmd, opt.prefixCmd...) + if r.cmd != "" { + fullCmd = append(fullCmd, r.cmd) } - + fullCmd = append(fullCmd, args...) fullCmd = append(fullCmd, opt.extraArgs...) cmd := exec.CommandContext(ctx, fullCmd[0], fullCmd[1:]...) diff --git a/webui/webui.go b/webui/webui.go index 1a2e8857..96b0340c 100644 --- a/webui/webui.go +++ b/webui/webui.go @@ -2,8 +2,10 @@ package webui import ( "net/http" + + "github.com/vearutop/statigz" ) func Handler() http.Handler { - + return statigz.FileServer(content, statigz.FSPrefix(contentPrefix)) } diff --git a/webui/webui_test.go b/webui/webui_test.go index 8ec98851..723d0de3 100644 --- a/webui/webui_test.go +++ b/webui/webui_test.go @@ -38,9 +38,9 @@ func TestServeIndexNoGzip(t *testing.T) { // Windows doesn't have the gzip binary, so we skip compression during the // go:generate step on Windows - if runtime.GOOS != "windows" && rr.Header().Get("Content-Encoding") != "gzip" { + if runtime.GOOS != "windows" && rr.Header().Get("Content-Encoding") != "" { t.Errorf("handler returned wrong content encoding: got %v want %v", - rr.Header().Get("Content-Encoding"), "gzip") + rr.Header().Get("Content-Encoding"), "") } }