summaryrefslogtreecommitdiff
path: root/modules/caddyhttp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r--modules/caddyhttp/app.go2
-rw-r--r--modules/caddyhttp/caddyauth/caddyauth.go2
-rw-r--r--modules/caddyhttp/celmatcher.go22
-rw-r--r--modules/caddyhttp/encode/encode.go6
-rw-r--r--modules/caddyhttp/fileserver/browse.go2
-rw-r--r--modules/caddyhttp/fileserver/staticfiles.go2
-rw-r--r--modules/caddyhttp/map/caddyfile.go2
-rw-r--r--modules/caddyhttp/map/map.go4
-rw-r--r--modules/caddyhttp/map/map_test.go22
-rw-r--r--modules/caddyhttp/matchers.go2
-rw-r--r--modules/caddyhttp/matchers_test.go2
-rw-r--r--modules/caddyhttp/replacer.go10
-rw-r--r--modules/caddyhttp/reverseproxy/admin.go2
-rw-r--r--modules/caddyhttp/reverseproxy/healthchecks.go2
-rw-r--r--modules/caddyhttp/reverseproxy/reverseproxy.go2
-rw-r--r--modules/caddyhttp/reverseproxy/streaming.go2
-rw-r--r--modules/caddyhttp/rewrite/rewrite.go2
-rw-r--r--modules/caddyhttp/routes.go8
-rw-r--r--modules/caddyhttp/server.go2
-rw-r--r--modules/caddyhttp/staticresp.go10
-rw-r--r--modules/caddyhttp/templates/frontmatter.go22
-rw-r--r--modules/caddyhttp/templates/tplcontext.go12
-rw-r--r--modules/caddyhttp/vars.go16
23 files changed, 75 insertions, 83 deletions
diff --git a/modules/caddyhttp/app.go b/modules/caddyhttp/app.go
index 82e052c..24069eb 100644
--- a/modules/caddyhttp/app.go
+++ b/modules/caddyhttp/app.go
@@ -202,7 +202,7 @@ func (app *App) Provision(ctx caddy.Context) error {
return fmt.Errorf("loading listener wrapper modules: %v", err)
}
var hasTLSPlaceholder bool
- for i, val := range vals.([]interface{}) {
+ for i, val := range vals.([]any) {
if _, ok := val.(*tlsPlaceholderWrapper); ok {
if i == 0 {
// putting the tls placeholder wrapper first is nonsensical because
diff --git a/modules/caddyhttp/caddyauth/caddyauth.go b/modules/caddyhttp/caddyauth/caddyauth.go
index 28b2e1b..ae30a08 100644
--- a/modules/caddyhttp/caddyauth/caddyauth.go
+++ b/modules/caddyhttp/caddyauth/caddyauth.go
@@ -62,7 +62,7 @@ func (a *Authentication) Provision(ctx caddy.Context) error {
if err != nil {
return fmt.Errorf("loading authentication providers: %v", err)
}
- for modName, modIface := range mods.(map[string]interface{}) {
+ for modName, modIface := range mods.(map[string]any) {
a.Providers[modName] = modIface.(Authenticator)
}
return nil
diff --git a/modules/caddyhttp/celmatcher.go b/modules/caddyhttp/celmatcher.go
index 81fea70..e7067c3 100644
--- a/modules/caddyhttp/celmatcher.go
+++ b/modules/caddyhttp/celmatcher.go
@@ -218,7 +218,7 @@ var httpRequestCELType = types.NewTypeValue("http.Request", traits.ReceiverType)
// drops allocation costs for CEL expression evaluations by roughly half.
type celHTTPRequest struct{ *http.Request }
-func (cr celHTTPRequest) ResolveName(name string) (interface{}, bool) {
+func (cr celHTTPRequest) ResolveName(name string) (any, bool) {
if name == "request" {
return cr, true
}
@@ -229,7 +229,7 @@ func (cr celHTTPRequest) Parent() interpreter.Activation {
return nil
}
-func (cr celHTTPRequest) ConvertToNative(typeDesc reflect.Type) (interface{}, error) {
+func (cr celHTTPRequest) ConvertToNative(typeDesc reflect.Type) (any, error) {
return cr.Request, nil
}
func (celHTTPRequest) ConvertToType(typeVal ref.Type) ref.Val {
@@ -241,8 +241,8 @@ func (cr celHTTPRequest) Equal(other ref.Val) ref.Val {
}
return types.ValOrErr(other, "%v is not comparable type", other)
}
-func (celHTTPRequest) Type() ref.Type { return httpRequestCELType }
-func (cr celHTTPRequest) Value() interface{} { return cr }
+func (celHTTPRequest) Type() ref.Type { return httpRequestCELType }
+func (cr celHTTPRequest) Value() any { return cr }
var pkixNameCELType = types.NewTypeValue("pkix.Name", traits.ReceiverType)
@@ -250,7 +250,7 @@ var pkixNameCELType = types.NewTypeValue("pkix.Name", traits.ReceiverType)
// methods to satisfy the ref.Val interface.
type celPkixName struct{ *pkix.Name }
-func (pn celPkixName) ConvertToNative(typeDesc reflect.Type) (interface{}, error) {
+func (pn celPkixName) ConvertToNative(typeDesc reflect.Type) (any, error) {
return pn.Name, nil
}
func (celPkixName) ConvertToType(typeVal ref.Type) ref.Val {
@@ -262,13 +262,13 @@ func (pn celPkixName) Equal(other ref.Val) ref.Val {
}
return types.ValOrErr(other, "%v is not comparable type", other)
}
-func (celPkixName) Type() ref.Type { return pkixNameCELType }
-func (pn celPkixName) Value() interface{} { return pn }
+func (celPkixName) Type() ref.Type { return pkixNameCELType }
+func (pn celPkixName) Value() any { return pn }
// celTypeAdapter can adapt our custom types to a CEL value.
type celTypeAdapter struct{}
-func (celTypeAdapter) NativeToValue(value interface{}) ref.Val {
+func (celTypeAdapter) NativeToValue(value any) ref.Val {
switch v := value.(type) {
case celHTTPRequest:
return v
@@ -545,17 +545,17 @@ func celMatcherJSONMacroExpander(funcName string) parser.MacroExpander {
// CELValueToMapStrList converts a CEL value to a map[string][]string
//
// Earlier validation stages should guarantee that the value has this type
-// at compile time, and that the runtime value type is map[string]interface{}.
+// at compile time, and that the runtime value type is map[string]any.
// The reason for the slight difference in value type is that CEL allows for
// map literals containing heterogeneous values, in this case string and list
// of string.
func CELValueToMapStrList(data ref.Val) (map[string][]string, error) {
- mapStrType := reflect.TypeOf(map[string]interface{}{})
+ mapStrType := reflect.TypeOf(map[string]any{})
mapStrRaw, err := data.ConvertToNative(mapStrType)
if err != nil {
return nil, err
}
- mapStrIface := mapStrRaw.(map[string]interface{})
+ mapStrIface := mapStrRaw.(map[string]any)
mapStrListStr := make(map[string][]string, len(mapStrIface))
for k, v := range mapStrIface {
switch val := v.(type) {
diff --git a/modules/caddyhttp/encode/encode.go b/modules/caddyhttp/encode/encode.go
index 8b49205..aae7280 100644
--- a/modules/caddyhttp/encode/encode.go
+++ b/modules/caddyhttp/encode/encode.go
@@ -71,7 +71,7 @@ func (enc *Encode) Provision(ctx caddy.Context) error {
if err != nil {
return fmt.Errorf("loading encoder modules: %v", err)
}
- for modName, modIface := range mods.(map[string]interface{}) {
+ for modName, modIface := range mods.(map[string]any) {
err = enc.addEncoding(modIface.(Encoding))
if err != nil {
return fmt.Errorf("adding encoding %s: %v", modName, err)
@@ -142,7 +142,7 @@ func (enc *Encode) addEncoding(e Encoding) error {
enc.writerPools = make(map[string]*sync.Pool)
}
enc.writerPools[ae] = &sync.Pool{
- New: func() interface{} {
+ New: func() any {
return e.NewEncoder()
},
}
@@ -418,7 +418,7 @@ type Precompressed interface {
}
var bufPool = sync.Pool{
- New: func() interface{} {
+ New: func() any {
return new(bytes.Buffer)
},
}
diff --git a/modules/caddyhttp/fileserver/browse.go b/modules/caddyhttp/fileserver/browse.go
index bdddc23..da97842 100644
--- a/modules/caddyhttp/fileserver/browse.go
+++ b/modules/caddyhttp/fileserver/browse.go
@@ -231,7 +231,7 @@ type templateContext struct {
// bufPool is used to increase the efficiency of file listings.
var bufPool = sync.Pool{
- New: func() interface{} {
+ New: func() any {
return new(bytes.Buffer)
},
}
diff --git a/modules/caddyhttp/fileserver/staticfiles.go b/modules/caddyhttp/fileserver/staticfiles.go
index 6bdb5af..93d529d 100644
--- a/modules/caddyhttp/fileserver/staticfiles.go
+++ b/modules/caddyhttp/fileserver/staticfiles.go
@@ -205,7 +205,7 @@ func (fsrv *FileServer) Provision(ctx caddy.Context) error {
if err != nil {
return fmt.Errorf("loading encoder modules: %v", err)
}
- for modName, modIface := range mods.(map[string]interface{}) {
+ for modName, modIface := range mods.(map[string]any) {
p, ok := modIface.(encode.Precompressed)
if !ok {
return fmt.Errorf("module %s is not precompressor", modName)
diff --git a/modules/caddyhttp/map/caddyfile.go b/modules/caddyhttp/map/caddyfile.go
index f1ee468..f38aff7 100644
--- a/modules/caddyhttp/map/caddyfile.go
+++ b/modules/caddyhttp/map/caddyfile.go
@@ -78,7 +78,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
// every other line maps one input to one or more outputs
in := h.Val()
- var outs []interface{}
+ var outs []any
for h.NextArg() {
val := h.ScalarVal()
if val == "-" {
diff --git a/modules/caddyhttp/map/map.go b/modules/caddyhttp/map/map.go
index 0a27aab..bbc1249 100644
--- a/modules/caddyhttp/map/map.go
+++ b/modules/caddyhttp/map/map.go
@@ -119,7 +119,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhtt
repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
// defer work until a variable is actually evaluated by using replacer's Map callback
- repl.Map(func(key string) (interface{}, bool) {
+ repl.Map(func(key string) (any, bool) {
// return early if the variable is not even a configured destination
destIdx := h.destinationIndex(key)
if destIdx < 0 {
@@ -187,7 +187,7 @@ type Mapping struct {
// Upon a match with the input, each output is positionally correlated
// with each destination of the parent handler. An output that is null
// (nil) will be treated as if it was not mapped at all.
- Outputs []interface{} `json:"outputs,omitempty"`
+ Outputs []any `json:"outputs,omitempty"`
re *regexp.Regexp
}
diff --git a/modules/caddyhttp/map/map_test.go b/modules/caddyhttp/map/map_test.go
index 26d6e85..fe233bf 100644
--- a/modules/caddyhttp/map/map_test.go
+++ b/modules/caddyhttp/map/map_test.go
@@ -15,7 +15,7 @@ func TestHandler(t *testing.T) {
for i, tc := range []struct {
handler Handler
reqURI string
- expect map[string]interface{}
+ expect map[string]any
}{
{
reqURI: "/foo",
@@ -25,11 +25,11 @@ func TestHandler(t *testing.T) {
Mappings: []Mapping{
{
Input: "/foo",
- Outputs: []interface{}{"FOO"},
+ Outputs: []any{"FOO"},
},
},
},
- expect: map[string]interface{}{
+ expect: map[string]any{
"output": "FOO",
},
},
@@ -41,11 +41,11 @@ func TestHandler(t *testing.T) {
Mappings: []Mapping{
{
InputRegexp: "(/abc)",
- Outputs: []interface{}{"ABC"},
+ Outputs: []any{"ABC"},
},
},
},
- expect: map[string]interface{}{
+ expect: map[string]any{
"output": "ABC",
},
},
@@ -57,11 +57,11 @@ func TestHandler(t *testing.T) {
Mappings: []Mapping{
{
InputRegexp: "(xyz)",
- Outputs: []interface{}{"...${1}..."},
+ Outputs: []any{"...${1}..."},
},
},
},
- expect: map[string]interface{}{
+ expect: map[string]any{
"output": "...xyz...",
},
},
@@ -74,11 +74,11 @@ func TestHandler(t *testing.T) {
Mappings: []Mapping{
{
InputRegexp: "(?i)(\\^|`|<|>|%|\\\\|\\{|\\}|\\|)",
- Outputs: []interface{}{"3"},
+ Outputs: []any{"3"},
},
},
},
- expect: map[string]interface{}{
+ expect: map[string]any{
"output": "3",
},
},
@@ -90,11 +90,11 @@ func TestHandler(t *testing.T) {
Mappings: []Mapping{
{
Input: "/foo",
- Outputs: []interface{}{"{testvar}"},
+ Outputs: []any{"{testvar}"},
},
},
},
- expect: map[string]interface{}{
+ expect: map[string]any{
"output": "testing",
},
},
diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go
index 82972e5..2eedaca 100644
--- a/modules/caddyhttp/matchers.go
+++ b/modules/caddyhttp/matchers.go
@@ -1032,7 +1032,7 @@ func (m *MatchNot) Provision(ctx caddy.Context) error {
if err != nil {
return fmt.Errorf("loading matcher sets: %v", err)
}
- for _, modMap := range matcherSets.([]map[string]interface{}) {
+ for _, modMap := range matcherSets.([]map[string]any) {
var ms MatcherSet
for _, modIface := range modMap {
ms = append(ms, modIface.(RequestMatcher))
diff --git a/modules/caddyhttp/matchers_test.go b/modules/caddyhttp/matchers_test.go
index f394921..bd4606b 100644
--- a/modules/caddyhttp/matchers_test.go
+++ b/modules/caddyhttp/matchers_test.go
@@ -807,7 +807,7 @@ func TestVarREMatcher(t *testing.T) {
req := &http.Request{URL: new(url.URL), Method: http.MethodGet}
repl := caddy.NewReplacer()
ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl)
- ctx = context.WithValue(ctx, VarsCtxKey, make(map[string]interface{}))
+ ctx = context.WithValue(ctx, VarsCtxKey, make(map[string]any))
req = req.WithContext(ctx)
addHTTPVarsToReplacer(repl, req, httptest.NewRecorder())
diff --git a/modules/caddyhttp/replacer.go b/modules/caddyhttp/replacer.go
index 2fa6517..bde58b7 100644
--- a/modules/caddyhttp/replacer.go
+++ b/modules/caddyhttp/replacer.go
@@ -57,7 +57,7 @@ func addHTTPVarsToReplacer(repl *caddy.Replacer, req *http.Request, w http.Respo
SetVar(req.Context(), "start_time", time.Now())
SetVar(req.Context(), "uuid", new(requestID))
- httpVars := func(key string) (interface{}, bool) {
+ httpVars := func(key string) (any, bool) {
if req != nil {
// query string parameters
if strings.HasPrefix(key, reqURIQueryReplPrefix) {
@@ -233,7 +233,7 @@ func addHTTPVarsToReplacer(repl *caddy.Replacer, req *http.Request, w http.Respo
// middleware variables
if strings.HasPrefix(key, varsReplPrefix) {
varName := key[len(varsReplPrefix):]
- tbl := req.Context().Value(VarsCtxKey).(map[string]interface{})
+ tbl := req.Context().Value(VarsCtxKey).(map[string]any)
raw := tbl[varName]
// variables can be dynamic, so always return true
// even when it may not be set; treat as empty then
@@ -258,7 +258,7 @@ func addHTTPVarsToReplacer(repl *caddy.Replacer, req *http.Request, w http.Respo
repl.Map(httpVars)
}
-func getReqTLSReplacement(req *http.Request, key string) (interface{}, bool) {
+func getReqTLSReplacement(req *http.Request, key string) (any, bool) {
if req == nil || req.TLS == nil {
return nil, false
}
@@ -279,7 +279,7 @@ func getReqTLSReplacement(req *http.Request, key string) (interface{}, bool) {
if strings.HasPrefix(field, "client.san.") {
field = field[len("client.san."):]
var fieldName string
- var fieldValue interface{}
+ var fieldValue any
switch {
case strings.HasPrefix(field, "dns_names"):
fieldName = "dns_names"
@@ -383,7 +383,7 @@ func getReqTLSReplacement(req *http.Request, key string) (interface{}, bool) {
}
// marshalPublicKey returns the byte encoding of pubKey.
-func marshalPublicKey(pubKey interface{}) ([]byte, error) {
+func marshalPublicKey(pubKey any) ([]byte, error) {
switch key := pubKey.(type) {
case *rsa.PublicKey:
return asn1.Marshal(key)
diff --git a/modules/caddyhttp/reverseproxy/admin.go b/modules/caddyhttp/reverseproxy/admin.go
index 771fa10..f64d1ec 100644
--- a/modules/caddyhttp/reverseproxy/admin.go
+++ b/modules/caddyhttp/reverseproxy/admin.go
@@ -76,7 +76,7 @@ func (adminUpstreams) handleUpstreams(w http.ResponseWriter, r *http.Request) er
// Iterate over the upstream pool (needs to be fast)
var rangeErr error
- hosts.Range(func(key, val interface{}) bool {
+ hosts.Range(func(key, val any) bool {
address, ok := key.(string)
if !ok {
rangeErr = caddy.APIError{
diff --git a/modules/caddyhttp/reverseproxy/healthchecks.go b/modules/caddyhttp/reverseproxy/healthchecks.go
index 317b283..eb98638 100644
--- a/modules/caddyhttp/reverseproxy/healthchecks.go
+++ b/modules/caddyhttp/reverseproxy/healthchecks.go
@@ -269,7 +269,7 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, upstre
// attach dialing information to this request
ctx := h.ctx.Context
ctx = context.WithValue(ctx, caddy.ReplacerCtxKey, caddy.NewReplacer())
- ctx = context.WithValue(ctx, caddyhttp.VarsCtxKey, map[string]interface{}{
+ ctx = context.WithValue(ctx, caddyhttp.VarsCtxKey, map[string]any{
dialInfoVarKey: dialInfo,
})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)
diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go
index 7061275..c800b39 100644
--- a/modules/caddyhttp/reverseproxy/reverseproxy.go
+++ b/modules/caddyhttp/reverseproxy/reverseproxy.go
@@ -1317,7 +1317,7 @@ func (brc bodyReadCloser) Close() error {
// bufPool is used for buffering requests and responses.
var bufPool = sync.Pool{
- New: func() interface{} {
+ New: func() any {
return new(bytes.Buffer)
},
}
diff --git a/modules/caddyhttp/reverseproxy/streaming.go b/modules/caddyhttp/reverseproxy/streaming.go
index 6bd1af2..298ab58 100644
--- a/modules/caddyhttp/reverseproxy/streaming.go
+++ b/modules/caddyhttp/reverseproxy/streaming.go
@@ -279,7 +279,7 @@ func (c switchProtocolCopier) copyToBackend(errc chan<- error) {
}
var streamingBufPool = sync.Pool{
- New: func() interface{} {
+ New: func() any {
// The Pool's New function should generally only return pointer
// types, since a pointer can be put into the return interface
// value without an allocation
diff --git a/modules/caddyhttp/rewrite/rewrite.go b/modules/caddyhttp/rewrite/rewrite.go
index da92269..ac8c4fc 100644
--- a/modules/caddyhttp/rewrite/rewrite.go
+++ b/modules/caddyhttp/rewrite/rewrite.go
@@ -283,7 +283,7 @@ func buildQueryString(qs string, repl *caddy.Replacer) string {
// consume the component and write the result
comp := qs[:end]
- comp, _ = repl.ReplaceFunc(comp, func(name string, val interface{}) (interface{}, error) {
+ comp, _ = repl.ReplaceFunc(comp, func(name string, val any) (any, error) {
if name == "http.request.uri.query" && wroteVal {
return val, nil // already escaped
}
diff --git a/modules/caddyhttp/routes.go b/modules/caddyhttp/routes.go
index b8771db..45cbd80 100644
--- a/modules/caddyhttp/routes.go
+++ b/modules/caddyhttp/routes.go
@@ -151,7 +151,7 @@ func (routes RouteList) ProvisionHandlers(ctx caddy.Context) error {
if err != nil {
return fmt.Errorf("route %d: loading handler modules: %v", i, err)
}
- for _, handler := range handlersIface.([]interface{}) {
+ for _, handler := range handlersIface.([]any) {
routes[i].Handlers = append(routes[i].Handlers, handler.(MiddlewareHandler))
}
@@ -315,9 +315,9 @@ func (ms MatcherSets) AnyMatch(req *http.Request) bool {
return len(ms) == 0
}
-// FromInterface fills ms from an interface{} value obtained from LoadModule.
-func (ms *MatcherSets) FromInterface(matcherSets interface{}) error {
- for _, matcherSetIfaces := range matcherSets.([]map[string]interface{}) {
+// FromInterface fills ms from an 'any' value obtained from LoadModule.
+func (ms *MatcherSets) FromInterface(matcherSets any) error {
+ for _, matcherSetIfaces := range matcherSets.([]map[string]any) {
var matcherSet MatcherSet
for _, matcher := range matcherSetIfaces {
reqMatcher, ok := matcher.(RequestMatcher)
diff --git a/modules/caddyhttp/server.go b/modules/caddyhttp/server.go
index 44a5888..c665e29 100644
--- a/modules/caddyhttp/server.go
+++ b/modules/caddyhttp/server.go
@@ -585,7 +585,7 @@ func PrepareRequest(r *http.Request, repl *caddy.Replacer, w http.ResponseWriter
// set up the context for the request
ctx := context.WithValue(r.Context(), caddy.ReplacerCtxKey, repl)
ctx = context.WithValue(ctx, ServerCtxKey, s)
- ctx = context.WithValue(ctx, VarsCtxKey, make(map[string]interface{}))
+ ctx = context.WithValue(ctx, VarsCtxKey, make(map[string]any))
ctx = context.WithValue(ctx, routeGroupCtxKey, make(map[string]struct{}))
var url2 url.URL // avoid letting this escape to the heap
ctx = context.WithValue(ctx, OriginalRequestCtxKey, originalRequest(r, &url2))
diff --git a/modules/caddyhttp/staticresp.go b/modules/caddyhttp/staticresp.go
index 9e12bd5..f0aea03 100644
--- a/modules/caddyhttp/staticresp.go
+++ b/modules/caddyhttp/staticresp.go
@@ -283,7 +283,7 @@ func cmdRespond(fl caddycmd.Flags) (int, error) {
// build headers map
hdr := make(http.Header)
for i, h := range respondCmdHeaders {
- key, val, found := cut(h, ":") // TODO: use strings.Cut() once Go 1.18 is our minimum
+ key, val, found := strings.Cut(h, ":")
key, val = strings.TrimSpace(key), strings.TrimSpace(val)
if !found || key == "" || val == "" {
return caddy.ExitCodeFailedStartup, fmt.Errorf("header %d: invalid format \"%s\" (expecting \"Field: value\")", i, h)
@@ -395,14 +395,6 @@ func cmdRespond(fl caddycmd.Flags) (int, error) {
select {}
}
-// TODO: delete this and use strings.Cut() once Go 1.18 is our minimum
-func cut(s, sep string) (before, after string, found bool) {
- if i := strings.Index(s, sep); i >= 0 {
- return s[:i], s[i+len(sep):], true
- }
- return s, "", false
-}
-
// respondCmdHeaders holds the parsed values from repeated use of the --header flag.
var respondCmdHeaders caddycmd.StringSlice
diff --git a/modules/caddyhttp/templates/frontmatter.go b/modules/caddyhttp/templates/frontmatter.go
index 9031e13..3f7bd0c 100644
--- a/modules/caddyhttp/templates/frontmatter.go
+++ b/modules/caddyhttp/templates/frontmatter.go
@@ -10,7 +10,7 @@ import (
"gopkg.in/yaml.v3"
)
-func extractFrontMatter(input string) (map[string]interface{}, string, error) {
+func extractFrontMatter(input string) (map[string]any, string, error) {
// get the bounds of the first non-empty line
var firstLineStart, firstLineEnd int
lineEmpty := true
@@ -35,7 +35,7 @@ func extractFrontMatter(input string) (map[string]interface{}, string, error) {
// see what kind of front matter there is, if any
var closingFence []string
- var fmParser func([]byte) (map[string]interface{}, error)
+ var fmParser func([]byte) (map[string]any, error)
for _, fmType := range supportedFrontMatterTypes {
if firstLine == fmType.FenceOpen {
closingFence = fmType.FenceClose
@@ -77,35 +77,35 @@ func extractFrontMatter(input string) (map[string]interface{}, string, error) {
return fm, body, nil
}
-func yamlFrontMatter(input []byte) (map[string]interface{}, error) {
- m := make(map[string]interface{})
+func yamlFrontMatter(input []byte) (map[string]any, error) {
+ m := make(map[string]any)
err := yaml.Unmarshal(input, &m)
return m, err
}
-func tomlFrontMatter(input []byte) (map[string]interface{}, error) {
- m := make(map[string]interface{})
+func tomlFrontMatter(input []byte) (map[string]any, error) {
+ m := make(map[string]any)
err := toml.Unmarshal(input, &m)
return m, err
}
-func jsonFrontMatter(input []byte) (map[string]interface{}, error) {
+func jsonFrontMatter(input []byte) (map[string]any, error) {
input = append([]byte{'{'}, input...)
input = append(input, '}')
- m := make(map[string]interface{})
+ m := make(map[string]any)
err := json.Unmarshal(input, &m)
return m, err
}
type parsedMarkdownDoc struct {
- Meta map[string]interface{} `json:"meta,omitempty"`
- Body string `json:"body,omitempty"`
+ Meta map[string]any `json:"meta,omitempty"`
+ Body string `json:"body,omitempty"`
}
type frontMatterType struct {
FenceOpen string
FenceClose []string
- ParseFunc func(input []byte) (map[string]interface{}, error)
+ ParseFunc func(input []byte) (map[string]any, error)
}
var supportedFrontMatterTypes = []frontMatterType{
diff --git a/modules/caddyhttp/templates/tplcontext.go b/modules/caddyhttp/templates/tplcontext.go
index bae24ba..96a341c 100644
--- a/modules/caddyhttp/templates/tplcontext.go
+++ b/modules/caddyhttp/templates/tplcontext.go
@@ -44,7 +44,7 @@ import (
type TemplateContext struct {
Root http.FileSystem
Req *http.Request
- Args []interface{} // defined by arguments to funcInclude
+ Args []any // defined by arguments to funcInclude
RespHeader WrappedHeader
CustomFuncs []template.FuncMap // functions added by plugins
@@ -99,7 +99,7 @@ func (c TemplateContext) OriginalReq() http.Request {
// Note that included files are NOT escaped, so you should only include
// trusted files. If it is not trusted, be sure to use escaping functions
// in your template.
-func (c TemplateContext) funcInclude(filename string, args ...interface{}) (string, error) {
+func (c TemplateContext) funcInclude(filename string, args ...any) (string, error) {
bodyBuf := bufPool.Get().(*bytes.Buffer)
bodyBuf.Reset()
@@ -304,7 +304,7 @@ func (TemplateContext) funcStripHTML(s string) string {
// funcMarkdown renders the markdown body as HTML. The resulting
// HTML is NOT escaped so that it can be rendered as HTML.
-func (TemplateContext) funcMarkdown(input interface{}) (string, error) {
+func (TemplateContext) funcMarkdown(input any) (string, error) {
inputStr := toString(input)
md := goldmark.New(
@@ -340,7 +340,7 @@ func (TemplateContext) funcMarkdown(input interface{}) (string, error) {
// splitFrontMatter parses front matter out from the beginning of input,
// and returns the separated key-value pairs and the body/content. input
// must be a "stringy" value.
-func (TemplateContext) funcSplitFrontMatter(input interface{}) (parsedMarkdownDoc, error) {
+func (TemplateContext) funcSplitFrontMatter(input any) (parsedMarkdownDoc, error) {
meta, body, err := extractFrontMatter(toString(input))
if err != nil {
return parsedMarkdownDoc{}, err
@@ -465,7 +465,7 @@ func (h WrappedHeader) Del(field string) string {
return ""
}
-func toString(input interface{}) string {
+func toString(input any) string {
switch v := input.(type) {
case string:
return v
@@ -479,7 +479,7 @@ func toString(input interface{}) string {
}
var bufPool = sync.Pool{
- New: func() interface{} {
+ New: func() any {
return new(bytes.Buffer)
},
}
diff --git a/modules/caddyhttp/vars.go b/modules/caddyhttp/vars.go
index e7a7dbb..08f3e70 100644
--- a/modules/caddyhttp/vars.go
+++ b/modules/caddyhttp/vars.go
@@ -37,7 +37,7 @@ func init() {
//
// The key is the variable name, and the value is the value of the
// variable. Both the name and value may use or contain placeholders.
-type VarsMiddleware map[string]interface{}
+type VarsMiddleware map[string]any
// CaddyModule returns the Caddy module information.
func (VarsMiddleware) CaddyModule() caddy.ModuleInfo {
@@ -48,7 +48,7 @@ func (VarsMiddleware) CaddyModule() caddy.ModuleInfo {
}
func (m VarsMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next Handler) error {
- vars := r.Context().Value(VarsCtxKey).(map[string]interface{})
+ vars := r.Context().Value(VarsCtxKey).(map[string]any)
repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
for k, v := range m {
keyExpanded := repl.ReplaceAll(k, "")
@@ -156,7 +156,7 @@ func (m VarsMatcher) Match(r *http.Request) bool {
return true
}
- vars := r.Context().Value(VarsCtxKey).(map[string]interface{})
+ vars := r.Context().Value(VarsCtxKey).(map[string]any)
repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
for key, vals := range m {
@@ -250,7 +250,7 @@ func (m MatchVarsRE) Provision(ctx caddy.Context) error {
// Match returns true if r matches m.
func (m MatchVarsRE) Match(r *http.Request) bool {
- vars := r.Context().Value(VarsCtxKey).(map[string]interface{})
+ vars := r.Context().Value(VarsCtxKey).(map[string]any)
repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
for k, rm := range m {
var varStr string
@@ -290,8 +290,8 @@ func (m MatchVarsRE) Validate() error {
// GetVar gets a value out of the context's variable table by key.
// If the key does not exist, the return value will be nil.
-func GetVar(ctx context.Context, key string) interface{} {
- varMap, ok := ctx.Value(VarsCtxKey).(map[string]interface{})
+func GetVar(ctx context.Context, key string) any {
+ varMap, ok := ctx.Value(VarsCtxKey).(map[string]any)
if !ok {
return nil
}
@@ -305,8 +305,8 @@ func GetVar(ctx context.Context, key string) interface{} {
// If the value is nil (note: non-nil interface with nil
// underlying value does not count) and the key exists in
// the table, the key+value will be deleted from the table.
-func SetVar(ctx context.Context, key string, value interface{}) {
- varMap, ok := ctx.Value(VarsCtxKey).(map[string]interface{})
+func SetVar(ctx context.Context, key string, value any) {
+ varMap, ok := ctx.Value(VarsCtxKey).(map[string]any)
if !ok {
return
}