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, 23:30 UTC
refactor: replace HasPrefix+TrimPrefix with CutPrefix (#7095)
Signed-off-by: gopherorg <gopherworld@icloud.com>
gopherorg committed
Jun 28, 2025 at 03:04 UTC
33c88bd2bb543a726274cdf52899edb0639cf5f6
2 files changed
+4
-4
modules/caddyevents/app.go
+2
-2
@@ -249,8 +249,8 @@ func (app *App) Emit(ctx caddy.Context, eventName string, data map[string]any) c
249
return e.Data, true
250
}
251
252
- if strings.HasPrefix(key, "event.data.") {
253
- key = strings.TrimPrefix(key, "event.data.")
252
+ if after, ok0 := strings.CutPrefix(key, "event.data."); ok0 {
253
+ key = after
254
if val, ok := e.Data[key]; ok {
255
return val, true
256
}
modules/caddyhttp/fileserver/staticfiles.go
+2
-2
@@ -684,11 +684,11 @@ func fileHidden(filename string, hide []string) bool {
684
return true
685
}
686
}
687
- } else if strings.HasPrefix(filename, h) {
687
+ } else if after, ok := strings.CutPrefix(filename, h); ok {
688
// if there is a separator in h, and filename is exactly
689
// prefixed with h, then we can do a prefix match so that
690
// "/foo" matches "/foo/bar" but not "/foobar".
691
- withoutPrefix := strings.TrimPrefix(filename, h)
691
+ withoutPrefix := after
692
if strings.HasPrefix(withoutPrefix, separator) {
693
return true
694
}