Use strings.ReplaceAll where applicable (#1046)

We already use it in the codebase, it's been around since 1.12, and is
considered best practice since it avoids hardcoding a magic number.
This commit is contained in:
James Raspass 2026-02-08 10:48:22 +00:00 committed by GitHub
parent 05f1ef7bb5
commit 142fada90f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View file

@ -26,7 +26,7 @@ func main() {
r.Put("/ping", Ping)
walkFunc := func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
route = strings.Replace(route, "/*/", "/", -1)
route = strings.ReplaceAll(route, "/*/", "/")
fmt.Printf("%s %s\n", method, route)
return nil
}

View file

@ -854,7 +854,7 @@ func walk(r Routes, walkFn WalkFunc, parentRoute string, parentMw ...func(http.H
}
fullRoute := parentRoute + route.Pattern
fullRoute = strings.Replace(fullRoute, "/*/", "/", -1)
fullRoute = strings.ReplaceAll(fullRoute, "/*/", "/")
if chain, ok := handler.(*ChainHandler); ok {
if err := walkFn(method, fullRoute, chain.Endpoint, append(mws, chain.Middlewares...)...); err != nil {