chore: Fix golangci-lint 2.12.1 findings (#7690)

This commit is contained in:
Zen Dodd 2026-05-07 17:40:26 +10:00 committed by GitHub
parent c7c9f3108a
commit d2172bea61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 31 additions and 16 deletions

View file

@ -234,7 +234,7 @@ func getModules() (standard, nonstandard, unknown []moduleInfo, err error) {
// not sure why), and since New() should return a pointer // not sure why), and since New() should return a pointer
// value, we need to dereference it first // value, we need to dereference it first
iface := any(modInfo.New()) iface := any(modInfo.New())
if rv := reflect.ValueOf(iface); rv.Kind() == reflect.Ptr { if rv := reflect.ValueOf(iface); rv.Kind() == reflect.Pointer {
iface = reflect.New(reflect.TypeOf(iface).Elem()).Elem().Interface() iface = reflect.New(reflect.TypeOf(iface).Elem()).Elem().Interface()
} }
modPkgPath := reflect.TypeOf(iface).PkgPath() modPkgPath := reflect.TypeOf(iface).PkgPath()

View file

@ -378,7 +378,7 @@ func (ctx Context) LoadModuleByID(id string, rawMsg json.RawMessage) (any, error
// value must be a pointer for unmarshaling into concrete type, even if // value must be a pointer for unmarshaling into concrete type, even if
// the module's concrete type is a slice or map; New() *should* return // the module's concrete type is a slice or map; New() *should* return
// a pointer, otherwise unmarshaling errors or panics will occur // a pointer, otherwise unmarshaling errors or panics will occur
if rv := reflect.ValueOf(val); rv.Kind() != reflect.Ptr { if rv := reflect.ValueOf(val); rv.Kind() != reflect.Pointer {
log.Printf("[WARNING] ModuleInfo.New() for module '%s' did not return a pointer,"+ log.Printf("[WARNING] ModuleInfo.New() for module '%s' did not return a pointer,"+
" so we are using reflection to make a pointer instead; please fix this by"+ " so we are using reflection to make a pointer instead; please fix this by"+
" using new(Type) or &Type notation in your module's New() function.", id) " using new(Type) or &Type notation in your module's New() function.", id)

View file

@ -281,7 +281,13 @@ func (fsrv *FileServer) browseApplyQueryParams(w http.ResponseWriter, r *http.Re
sortParam = sortCookie.Value sortParam = sortCookie.Value
} }
case sortByName, sortByNameDirFirst, sortBySize, sortByTime: case sortByName, sortByNameDirFirst, sortBySize, sortByTime:
http.SetCookie(w, &http.Cookie{Name: "sort", Value: sortParam, Secure: r.TLS != nil}) http.SetCookie(w, &http.Cookie{ //nolint:gosec // Secure depends on whether the request itself used TLS
Name: "sort",
Value: sortParam,
Secure: r.TLS != nil,
HttpOnly: true,
SameSite: http.SameSiteLaxMode,
})
} }
// then figure out the order // then figure out the order
@ -292,7 +298,13 @@ func (fsrv *FileServer) browseApplyQueryParams(w http.ResponseWriter, r *http.Re
orderParam = orderCookie.Value orderParam = orderCookie.Value
} }
case sortOrderAsc, sortOrderDesc: case sortOrderAsc, sortOrderDesc:
http.SetCookie(w, &http.Cookie{Name: "order", Value: orderParam, Secure: r.TLS != nil}) http.SetCookie(w, &http.Cookie{ //nolint:gosec // Secure depends on whether the request itself used TLS
Name: "order",
Value: orderParam,
Secure: r.TLS != nil,
HttpOnly: true,
SameSite: http.SameSiteLaxMode,
})
} }
// finally, apply the sorting and limiting // finally, apply the sorting and limiting

View file

@ -785,7 +785,7 @@ func redirect(w http.ResponseWriter, r *http.Request, toPath string) error {
if r.URL.RawQuery != "" { if r.URL.RawQuery != "" {
toPath += "?" + r.URL.RawQuery toPath += "?" + r.URL.RawQuery
} }
http.Redirect(w, r, toPath, http.StatusPermanentRedirect) http.Redirect(w, r, toPath, http.StatusPermanentRedirect) //nolint:gosec // toPath is a same-origin path and leading // is stripped above
return nil return nil
} }

View file

@ -664,10 +664,12 @@ func (s CookieHashSelection) Select(pool UpstreamPool, req *http.Request, w http
return upstream return upstream
} }
cookie := &http.Cookie{ cookie := &http.Cookie{
Name: s.Name, Name: s.Name,
Value: sha, Value: sha,
Path: "/", Path: "/",
Secure: false, Secure: false,
HttpOnly: true,
SameSite: http.SameSiteLaxMode,
} }
isProxyHttps := false isProxyHttps := false
if trusted, ok := caddyhttp.GetVar(req.Context(), caddyhttp.TrustedProxyVarKey).(bool); ok && trusted { if trusted, ok := caddyhttp.GetVar(req.Context(), caddyhttp.TrustedProxyVarKey).(bool); ok && trusted {

View file

@ -18,6 +18,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"slices"
"strings" "strings"
"github.com/caddyserver/caddy/v2" "github.com/caddyserver/caddy/v2"
@ -241,8 +242,8 @@ func (routes RouteList) Compile(next Handler) Handler {
mid = append(mid, wrapRoute(route)) mid = append(mid, wrapRoute(route))
} }
stack := next stack := next
for i := len(mid) - 1; i >= 0; i-- { for _, middleware := range slices.Backward(mid) {
stack = mid[i](stack) stack = middleware(stack)
} }
return stack return stack
} }
@ -305,8 +306,8 @@ func wrapRoute(route Route) Middleware {
} }
// compile this route's handler stack // compile this route's handler stack
for i := len(route.middleware) - 1; i >= 0; i-- { for _, middleware := range slices.Backward(route.middleware) {
nextCopy = route.middleware[i](nextCopy) nextCopy = middleware(nextCopy)
} }
// Apply metrics instrumentation once for the entire route, // Apply metrics instrumentation once for the entire route,

View file

@ -1085,11 +1085,11 @@ func strictUntrustedClientIp(r *http.Request, headers []string, trusted []netip.
for _, headerName := range headers { for _, headerName := range headers {
parts := strings.Split(strings.Join(r.Header.Values(headerName), ","), ",") parts := strings.Split(strings.Join(r.Header.Values(headerName), ","), ",")
for i := len(parts) - 1; i >= 0; i-- { for _, part := range slices.Backward(parts) {
// Some proxies may retain the port number, so split if possible // Some proxies may retain the port number, so split if possible
host, _, err := net.SplitHostPort(parts[i]) host, _, err := net.SplitHostPort(part)
if err != nil { if err != nil {
host = parts[i] host = part
} }
// Remove any zone identifier from the IP address // Remove any zone identifier from the IP address