Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 17:15 UTC
chore: Dumb `prealloc` lint fix (#7430)
Francis Lavoie committed
Jan 13, 2026 at 14:13 UTC
90972fbebc74cd62ff50c0e0f6a1c99deca098ac
8 files changed
+17
-6
caddyconfig/caddyfile/parse.go
+1
-1
@@ -761,7 +761,7 @@ type ServerBlock struct {
761
}
762
763
func (sb ServerBlock) GetKeysText() []string {
764
- res := []string{}
764
+ res := make([]string, 0, len(sb.Keys))
765
for _, k := range sb.Keys {
766
res = append(res, k.Text)
767
}
caddyconfig/httpcaddyfile/builtins.go
+1
@@ -930,6 +930,7 @@ func parseLogHelper(h Helper, globalLogNames map[string]struct{}) ([]ConfigValue
930
// modifications to the parsing behavior.
931
parseAsGlobalOption := globalLogNames != nil
932
933
+ // nolint:prealloc
934
var configValues []ConfigValue
935
936
// Logic below expects that a name is always present when a
modules/caddyhttp/fileserver/matcher.go
+1
-1
@@ -404,7 +404,7 @@ func (m MatchFile) selectFile(r *http.Request) (bool, error) {
404
}
405
406
// for each glob result, combine all the forms of the path
407
- var candidates []matchCandidate
407
+ candidates := make([]matchCandidate, 0, len(globResults))
408
for _, result := range globResults {
409
candidates = append(candidates, matchCandidate{
410
fullpath: result,
modules/caddyhttp/headers/caddyfile.go
+1
-3
@@ -168,8 +168,6 @@ func parseReqHdrCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue,
168
}
169
h.Next() // consume the directive name again (matcher parsing resets)
170
171
- configValues := []httpcaddyfile.ConfigValue{}
172
-
171
if !h.NextArg() {
172
return nil, h.ArgErr()
173
}
@@ -204,7 +202,7 @@ func parseReqHdrCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue,
202
return nil, h.Err(err.Error())
203
}
204
207
- configValues = append(configValues, h.NewRoute(matcherSet, hdr)...)
205
+ configValues := h.NewRoute(matcherSet, hdr)
206
207
if h.NextArg() {
208
return nil, h.ArgErr()
modules/caddyhttp/push/caddyfile.go
+1
@@ -64,6 +64,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
64
var err error
65
66
// include current token, which we treat as an argument here
67
+ // nolint:prealloc
68
args := []string{h.Val()}
69
args = append(args, h.RemainingArgs()...)
70
modules/caddyhttp/rewrite/caddyfile.go
+1
@@ -173,6 +173,7 @@ func parseCaddyfileURI(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, err
173
if hasArgs {
174
return nil, h.Err("Cannot specify uri query rewrites in both argument and block")
175
}
176
+ // nolint:prealloc
177
queryArgs := []string{h.Val()}
178
queryArgs = append(queryArgs, h.RemainingArgs()...)
179
err := applyQueryOps(h, rewr.Query, queryArgs)
modules/caddyhttp/server.go
+1
@@ -1010,6 +1010,7 @@ func isTrustedClientIP(ipAddr netip.Addr, trusted []netip.Prefix) bool {
1010
// then the first value from those headers is used.
1011
func trustedRealClientIP(r *http.Request, headers []string, clientIP string) string {
1012
// Read all the values of the configured client IP headers, in order
1013
+ // nolint:prealloc
1014
var values []string
1015
for _, field := range headers {
1016
values = append(values, r.Header.Values(field)...)
modules/caddyhttp/staticresp.go
+10
-1
@@ -257,7 +257,16 @@ func (s StaticResponse) ServeHTTP(w http.ResponseWriter, r *http.Request, next H
257
return nil
258
}
259
260
-func buildHTTPServer(i int, port uint, addr string, statusCode int, hdr http.Header, body string, accessLog bool) (*Server, error) {
260
+func buildHTTPServer(
261
+ i int,
262
+ port uint,
263
+ addr string,
264
+ statusCode int,
265
+ hdr http.Header,
266
+ body string,
267
+ accessLog bool,
268
+) (*Server, error) {
269
+ // nolint:prealloc
270
var handlers []json.RawMessage
271
272
// response body supports a basic template; evaluate it