Skip to content
Myr

RouterGroup.Handle regular match optimization of http method (#2685)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by heige · committed by GitHub · parent 7313b8f · Browse files · 1 file+6 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: thinkerou <thinkerou@gmail.com>
  • Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>

Diff stats

1 file+6 added−1 removed

  • other:+6 added−1 removed

1 file+6 added−1 removed

modified:routergroup.go+6 added-1 removed
9 unmodified lines
10 "regexp"11 "strings"12)1314var (15 // reg match english letters for http method name16 regEnLetter = regexp.MustCompile("^[A-Z]+$")17)1819// IRouter defines all router handle interface includes single and group router.20type IRouter interface {21 IRoutes22 Group(string, ...HandlerFunc) *RouterGroup
68 unmodified lines
91// This function is intended for bulk loading and to allow the usage of less92// frequently used, non-standardized or custom methods (e.g. for internal93// communication with a proxy).94func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) IRoutes {90 if matches, err := regexp.MatchString("^[A-Z]+$", httpMethod); !matches || err != nil {95 if matched := regEnLetter.MatchString(httpMethod); !matched {96 panic("http method " + httpMethod + " is not valid")97 }98 return group.handle(httpMethod, relativePath, handlers)99}
136 unmodified lines