Skip to content

Commit c0bc886

Browse files
imxybaldas
authored andcommitted
refactor: use strings.ReplaceAll directly
1 parent f22ba67 commit c0bc886

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

middleware/cors.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ func CORSWithConfig(config CORSConfig) echo.MiddlewareFunc {
150150
allowOriginPatterns := []string{}
151151
for _, origin := range config.AllowOrigins {
152152
pattern := regexp.QuoteMeta(origin)
153-
pattern = strings.Replace(pattern, "\\*", ".*", -1)
154-
pattern = strings.Replace(pattern, "\\?", ".", -1)
153+
pattern = strings.ReplaceAll(pattern, "\\*", ".*")
154+
pattern = strings.ReplaceAll(pattern, "\\?", ".")
155155
pattern = "^" + pattern + "$"
156156
allowOriginPatterns = append(allowOriginPatterns, pattern)
157157
}

middleware/middleware.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ func rewriteRulesRegex(rewrite map[string]string) map[*regexp.Regexp]string {
3838
rulesRegex := map[*regexp.Regexp]string{}
3939
for k, v := range rewrite {
4040
k = regexp.QuoteMeta(k)
41-
k = strings.Replace(k, `\*`, "(.*?)", -1)
41+
k = strings.ReplaceAll(k, `\*`, "(.*?)")
4242
if strings.HasPrefix(k, `\^`) {
43-
k = strings.Replace(k, `\^`, "^", -1)
43+
k = strings.ReplaceAll(k, `\^`, "^")
4444
}
4545
k = k + "$"
4646
rulesRegex[regexp.MustCompile(k)] = v

0 commit comments

Comments
 (0)