diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d3577d4..d03470a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,7 +42,7 @@ jobs: deploy-release-packagecloud: if: startsWith(github.ref, 'refs/tags/v') needs: release - name: Deploy Nonpublic PackageCloud + name: Deploy Production PackageCloud runs-on: ubuntu-latest steps: - name: Download release files diff --git a/package/fogwillow.service b/package/fogwillow.service index d332d4b..eff4b4b 100644 --- a/package/fogwillow.service +++ b/package/fogwillow.service @@ -1,6 +1,6 @@ # Systemd service unit for fogwillow. [Unit] -Description=fogwillow - High performance UDP logger. +Description=fogwillow - High performance UDP->File logger. Like a syslogd server. Wants=network-online.target After=network-online.target diff --git a/package/package.sh b/package/package.sh index 57651bc..a78ae8b 100755 --- a/package/package.sh +++ b/package/package.sh @@ -26,7 +26,6 @@ read -r -d '' PACKAGE_ARGS <<- PACKAGE_ARGS --after-install package/after-install.sh --before-install package/before-install.sh --before-remove package/before-remove.sh - --deb-no-default-config-files --description='${DESC}' --iteration ${ITERATION} --license ${LICENSE} diff --git a/pkg/api/handlers.go b/pkg/api/handlers.go index 81c1ee9..f621afc 100644 --- a/pkg/api/handlers.go +++ b/pkg/api/handlers.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "path/filepath" + "strconv" "strings" "time" @@ -66,7 +67,7 @@ func (a *API) listHandler(resp http.ResponseWriter, r *http.Request) { }) } - writeJSON(resp, http.StatusOK, entries) + writeJSON(resp, http.StatusOK, entries, strconv.Itoa(len(entries))+" entries") } // fileHandler handles GET /api/file/{path} and streams the file contents. @@ -137,7 +138,7 @@ func (a *API) deleteHandler(resp http.ResponseWriter, r *http.Request) { } } - writeJSON(resp, http.StatusOK, DeleteResult{Deleted: len(deleted), Paths: deleted}) + writeJSON(resp, http.StatusOK, DeleteResult{Deleted: len(deleted), Paths: deleted}, strconv.Itoa(len(deleted))+" deleted") } // resolveForDelete returns the filesystem paths to act on for the given pattern. @@ -177,17 +178,21 @@ func (a *API) deleteAllHandler(resp http.ResponseWriter, _ *http.Request) { } } - writeJSON(resp, http.StatusOK, map[string]int{"deleted": count}) + writeJSON(resp, http.StatusOK, DeleteResult{Deleted: count, Paths: []string{a.outputPath}}, strconv.Itoa(count)+" deleted") } // writeJSON writes data as a JSON response body with the given status code. -func writeJSON(resp http.ResponseWriter, status int, data any) { +func writeJSON(resp http.ResponseWriter, status int, data any, info string) { body, err := json.Marshal(data) if err != nil { http.Error(resp, `{"error":"internal server error"}`, http.StatusInternalServerError) return } + if info != "" { + resp.Header().Set("X-Info", info) + } + resp.Header().Set("Content-Type", "application/json") resp.WriteHeader(status) _, _ = resp.Write(body) @@ -195,5 +200,12 @@ func writeJSON(resp http.ResponseWriter, status int, data any) { // writeError writes a JSON error response. func writeError(resp http.ResponseWriter, status int, msg string) { - writeJSON(resp, status, map[string]string{"error": msg}) + const maxInfoLength = 100 + + info := strings.TrimSpace(msg) + if len(info) > maxInfoLength { + info = info[:maxInfoLength] + "..." + } + + writeJSON(resp, status, map[string]string{"error": msg}, info) } diff --git a/pkg/api/uploads.go b/pkg/api/uploads.go index a40aa91..b311e58 100644 --- a/pkg/api/uploads.go +++ b/pkg/api/uploads.go @@ -39,9 +39,9 @@ func (a *API) uploadHandler(resp http.ResponseWriter, req *http.Request) { case err != nil: writeError(resp, http.StatusInternalServerError, err.Error()) case created: - writeJSON(resp, http.StatusCreated, map[string]string{"path": relPath}) + writeJSON(resp, http.StatusCreated, map[string]string{"path": relPath}, "created") default: - writeJSON(resp, http.StatusOK, map[string]string{"path": relPath}) + writeJSON(resp, http.StatusOK, map[string]string{"path": relPath}, "updated") } } diff --git a/pkg/httpserver/accesslog.go b/pkg/httpserver/accesslog.go index a643605..e1d3f93 100644 --- a/pkg/httpserver/accesslog.go +++ b/pkg/httpserver/accesslog.go @@ -13,9 +13,9 @@ const ( // LogFileMode is the mode for the access log file. LogFileMode = 0o644 // CombinedLogFormat is from Apache: host ident user time "request" status bytes "referer" "user-agent". - CombinedLogFormat = `%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"` + CombinedLogFormat = `%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i" "%{X-Info}o"` // MaxStupidValue is a stupid big value for minimizing config inputs. - MaxStupidValue = uint(9999999) // for comparing with config. + MaxStupidValue = uint(9999999) // for comparing with config.ß ) // newAccessLog creates a rotating access log writer from config.