chore: Dumb prealloc lint fix (#7430)

This commit is contained in:
Francis Lavoie
2026-01-13 14:13:43 -05:00
committed by GitHub
parent 28103aafba
commit 90972fbebc
8 changed files with 17 additions and 6 deletions

View File

@@ -404,7 +404,7 @@ func (m MatchFile) selectFile(r *http.Request) (bool, error) {
}
// for each glob result, combine all the forms of the path
var candidates []matchCandidate
candidates := make([]matchCandidate, 0, len(globResults))
for _, result := range globResults {
candidates = append(candidates, matchCandidate{
fullpath: result,

View File

@@ -168,8 +168,6 @@ func parseReqHdrCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue,
}
h.Next() // consume the directive name again (matcher parsing resets)
configValues := []httpcaddyfile.ConfigValue{}
if !h.NextArg() {
return nil, h.ArgErr()
}
@@ -204,7 +202,7 @@ func parseReqHdrCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue,
return nil, h.Err(err.Error())
}
configValues = append(configValues, h.NewRoute(matcherSet, hdr)...)
configValues := h.NewRoute(matcherSet, hdr)
if h.NextArg() {
return nil, h.ArgErr()

View File

@@ -64,6 +64,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
var err error
// include current token, which we treat as an argument here
// nolint:prealloc
args := []string{h.Val()}
args = append(args, h.RemainingArgs()...)

View File

@@ -173,6 +173,7 @@ func parseCaddyfileURI(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, err
if hasArgs {
return nil, h.Err("Cannot specify uri query rewrites in both argument and block")
}
// nolint:prealloc
queryArgs := []string{h.Val()}
queryArgs = append(queryArgs, h.RemainingArgs()...)
err := applyQueryOps(h, rewr.Query, queryArgs)

View File

@@ -1010,6 +1010,7 @@ func isTrustedClientIP(ipAddr netip.Addr, trusted []netip.Prefix) bool {
// then the first value from those headers is used.
func trustedRealClientIP(r *http.Request, headers []string, clientIP string) string {
// Read all the values of the configured client IP headers, in order
// nolint:prealloc
var values []string
for _, field := range headers {
values = append(values, r.Header.Values(field)...)

View File

@@ -257,7 +257,16 @@ func (s StaticResponse) ServeHTTP(w http.ResponseWriter, r *http.Request, next H
return nil
}
func buildHTTPServer(i int, port uint, addr string, statusCode int, hdr http.Header, body string, accessLog bool) (*Server, error) {
func buildHTTPServer(
i int,
port uint,
addr string,
statusCode int,
hdr http.Header,
body string,
accessLog bool,
) (*Server, error) {
// nolint:prealloc
var handlers []json.RawMessage
// response body supports a basic template; evaluate it