refactor: replace HasPrefix+TrimPrefix with CutPrefix (#7095)

Signed-off-by: gopherorg <gopherworld@icloud.com>
This commit is contained in:
gopherorg 2025-06-28 03:04:09 +08:00 committed by GitHub
parent 11c6daecd7
commit 33c88bd2bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View File

@ -249,8 +249,8 @@ func (app *App) Emit(ctx caddy.Context, eventName string, data map[string]any) c
return e.Data, true
}
if strings.HasPrefix(key, "event.data.") {
key = strings.TrimPrefix(key, "event.data.")
if after, ok0 := strings.CutPrefix(key, "event.data."); ok0 {
key = after
if val, ok := e.Data[key]; ok {
return val, true
}

View File

@ -684,11 +684,11 @@ func fileHidden(filename string, hide []string) bool {
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
// prefixed with h, then we can do a prefix match so that
// "/foo" matches "/foo/bar" but not "/foobar".
withoutPrefix := strings.TrimPrefix(filename, h)
withoutPrefix := after
if strings.HasPrefix(withoutPrefix, separator) {
return true
}