Skip to content

Commit

Permalink
RouterGroup.Handle regular match optimization of http method (#2685)
Browse files Browse the repository at this point in the history
Co-authored-by: thinkerou <thinkerou@gmail.com>
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
3 people authored Apr 21, 2021
1 parent 7313b8f commit f1da692
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion routergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import (
"strings"
)

var (
// reg match english letters for http method name
regEnLetter = regexp.MustCompile("^[A-Z]+$")
)

// IRouter defines all router handle interface includes single and group router.
type IRouter interface {
IRoutes
Expand Down Expand Up @@ -87,7 +92,7 @@ func (group *RouterGroup) handle(httpMethod, relativePath string, handlers Handl
// frequently used, non-standardized or custom methods (e.g. for internal
// communication with a proxy).
func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) IRoutes {
if matches, err := regexp.MatchString("^[A-Z]+$", httpMethod); !matches || err != nil {
if matched := regEnLetter.MatchString(httpMethod); !matched {
panic("http method " + httpMethod + " is not valid")
}
return group.handle(httpMethod, relativePath, handlers)
Expand Down

0 comments on commit f1da692

Please sign in to comment.