Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package/fogwillow.service
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 0 additions & 1 deletion package/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
22 changes: 17 additions & 5 deletions pkg/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -177,23 +178,34 @@ 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)
}

// 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)
}
4 changes: 2 additions & 2 deletions pkg/api/uploads.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/httpserver/accesslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down