Skip to content

Commit

Permalink
refactor: use switch for faster check
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Sep 22, 2022
1 parent dd98f33 commit 7216fa7
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions redirects.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"github.com/ucarion/urlpath"
)

var validStatuses = []int{200, 301, 302, 303, 307, 308, 404, 410, 451}

// A Rule represents a single redirection or rewrite rule.
type Rule struct {
// From is the path which is matched to perform the rule.
Expand Down Expand Up @@ -172,10 +170,9 @@ func parseStatus(s string) (code int, err error) {
}

func isValidStatusCode(status int) bool {
for _, validStatus := range validStatuses {
if validStatus == status {
return true
}
switch status {
case 200, 301, 302, 303, 307, 308, 404, 410, 451:
return true
}
return false
}

0 comments on commit 7216fa7

Please sign in to comment.