mirror of
https://github.com/caddyserver/caddy.git
synced 2025-07-09 03:04:57 -04:00
refactor: replace HasPrefix+TrimPrefix with CutPrefix (#7095)
Signed-off-by: gopherorg <gopherworld@icloud.com>
This commit is contained in:
parent
11c6daecd7
commit
33c88bd2bb
@ -249,8 +249,8 @@ func (app *App) Emit(ctx caddy.Context, eventName string, data map[string]any) c
|
|||||||
return e.Data, true
|
return e.Data, true
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(key, "event.data.") {
|
if after, ok0 := strings.CutPrefix(key, "event.data."); ok0 {
|
||||||
key = strings.TrimPrefix(key, "event.data.")
|
key = after
|
||||||
if val, ok := e.Data[key]; ok {
|
if val, ok := e.Data[key]; ok {
|
||||||
return val, true
|
return val, true
|
||||||
}
|
}
|
||||||
|
@ -684,11 +684,11 @@ func fileHidden(filename string, hide []string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if strings.HasPrefix(filename, h) {
|
} else if after, ok := strings.CutPrefix(filename, h); ok {
|
||||||
// if there is a separator in h, and filename is exactly
|
// if there is a separator in h, and filename is exactly
|
||||||
// prefixed with h, then we can do a prefix match so that
|
// prefixed with h, then we can do a prefix match so that
|
||||||
// "/foo" matches "/foo/bar" but not "/foobar".
|
// "/foo" matches "/foo/bar" but not "/foobar".
|
||||||
withoutPrefix := strings.TrimPrefix(filename, h)
|
withoutPrefix := after
|
||||||
if strings.HasPrefix(withoutPrefix, separator) {
|
if strings.HasPrefix(withoutPrefix, separator) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user