18a9f6624e
CI / Test (linux/amd64) (pull_request) Successful in 29s
CI / Lint (pull_request) Failing after 16s
CI / Build (windows/amd64) (pull_request) Successful in 20s
CI / Build (linux/amd64) (pull_request) Successful in 20s
CI / Build (linux/arm64) (pull_request) Successful in 21s
The bump from golangci-lint-action@v6 → v7 (which downloads the v2.x binary) was blocking CI lint with 'unsupported version of the configuration: ""' because .golangci.yml was still in the v1 schema. Migrate the config to v2: * version: "2" prelude * disable-all → default: none * linters-settings → linters.settings * gofumpt + goimports move into formatters.enable + formatters.settings * exclude-rules move into linters.exclusions.rules * gosimple drops (folded into staticcheck in v2) Fix the four lint hits in the new P2R-02 code: * host_bandwidth.go: convert hostBandwidthRequest directly to hostBandwidthView via type conversion (S1016) * ui_repo.go: drop unparam savedSection + status arguments from renderRepoPage (always "" / always 422 — split GET render from validation-fail render) * ui_schedules.go: gofumpt formatting on the scheduleEditPage struct Add only-new-issues: true to the lint job. The repo carries ~90 pre-existing findings (gofumpt drift × 31, misspell × 25, missing godoc × 10, bodyclose × 6, errcheck × 12, …) accumulated before lint was actually wired into CI. Without this gate, every PR would fail on baseline noise instead of its own changes. Track the cleanup as X-06 in tasks.md so the gate is temporary.
63 lines
1.9 KiB
Go
63 lines
1.9 KiB
Go
// host_bandwidth.go — REST API for /api/hosts/{id}/bandwidth.
|
|
//
|
|
// Host-wide upload/download caps (KB/s). Applied to every restic
|
|
// invocation as --limit-upload / --limit-download. Pass null /
|
|
// omit a field to clear that cap.
|
|
package http
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
stdhttp "net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"gitea.dcglab.co.uk/steve/restic-manager/internal/store"
|
|
)
|
|
|
|
type hostBandwidthRequest struct {
|
|
BandwidthUpKBps *int `json:"bandwidth_up_kbps"`
|
|
BandwidthDownKBps *int `json:"bandwidth_down_kbps"`
|
|
}
|
|
|
|
type hostBandwidthView struct {
|
|
BandwidthUpKBps *int `json:"bandwidth_up_kbps"`
|
|
BandwidthDownKBps *int `json:"bandwidth_down_kbps"`
|
|
}
|
|
|
|
func (s *Server) handleUpdateHostBandwidth(w stdhttp.ResponseWriter, r *stdhttp.Request) {
|
|
if !s.authedUser(r) {
|
|
writeJSONError(w, stdhttp.StatusUnauthorized, "unauthorized", "")
|
|
return
|
|
}
|
|
hostID := chi.URLParam(r, "id")
|
|
if _, err := s.deps.Store.GetHost(r.Context(), hostID); err != nil {
|
|
if errors.Is(err, store.ErrNotFound) {
|
|
writeJSONError(w, stdhttp.StatusNotFound, "host_not_found", "")
|
|
return
|
|
}
|
|
writeJSONError(w, stdhttp.StatusInternalServerError, "internal", "")
|
|
return
|
|
}
|
|
var req hostBandwidthRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
writeJSONError(w, stdhttp.StatusBadRequest, "invalid_json", err.Error())
|
|
return
|
|
}
|
|
if req.BandwidthUpKBps != nil && *req.BandwidthUpKBps < 0 {
|
|
writeJSONError(w, stdhttp.StatusBadRequest, "invalid_value",
|
|
"bandwidth_up_kbps must be non-negative")
|
|
return
|
|
}
|
|
if req.BandwidthDownKBps != nil && *req.BandwidthDownKBps < 0 {
|
|
writeJSONError(w, stdhttp.StatusBadRequest, "invalid_value",
|
|
"bandwidth_down_kbps must be non-negative")
|
|
return
|
|
}
|
|
if err := s.deps.Store.SetHostBandwidth(r.Context(), hostID, req.BandwidthUpKBps, req.BandwidthDownKBps); err != nil {
|
|
writeJSONError(w, stdhttp.StatusInternalServerError, "internal", err.Error())
|
|
return
|
|
}
|
|
writeJSON(w, stdhttp.StatusOK, hostBandwidthView(req))
|
|
}
|