mirror of
https://github.com/caddyserver/caddy.git
synced 2025-12-08 06:09:53 +00:00
chore: Use slices package where possible (#6585)
* chore: Use slices package where possible * More, mostly using ContainsFunc * Even more slice operations
This commit is contained in:
parent
9dda8fbf84
commit
2faeac0a10
21 changed files with 142 additions and 268 deletions
|
|
@ -18,6 +18,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
|
|
@ -126,7 +127,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhtt
|
|||
// defer work until a variable is actually evaluated by using replacer's Map callback
|
||||
repl.Map(func(key string) (any, bool) {
|
||||
// return early if the variable is not even a configured destination
|
||||
destIdx := h.destinationIndex(key)
|
||||
destIdx := slices.Index(h.Destinations, key)
|
||||
if destIdx < 0 {
|
||||
return nil, false
|
||||
}
|
||||
|
|
@ -170,17 +171,6 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhtt
|
|||
return next.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
// destinationIndex returns the positional index of the destination
|
||||
// is name is a known destination; otherwise it returns -1.
|
||||
func (h Handler) destinationIndex(name string) int {
|
||||
for i, dest := range h.Destinations {
|
||||
if dest == name {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// Mapping describes a mapping from input to outputs.
|
||||
type Mapping struct {
|
||||
// The input value to match. Must be distinct from other mappings.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue