custom_verb.go 594 B

1234567891011121314151617181920212223242526272829
  1. package restful
  2. import (
  3. "fmt"
  4. "regexp"
  5. )
  6. var (
  7. customVerbReg = regexp.MustCompile(":([A-Za-z]+)$")
  8. )
  9. func hasCustomVerb(routeToken string) bool {
  10. return customVerbReg.MatchString(routeToken)
  11. }
  12. func isMatchCustomVerb(routeToken string, pathToken string) bool {
  13. rs := customVerbReg.FindStringSubmatch(routeToken)
  14. if len(rs) < 2 {
  15. return false
  16. }
  17. customVerb := rs[1]
  18. specificVerbReg := regexp.MustCompile(fmt.Sprintf(":%s$", customVerb))
  19. return specificVerbReg.MatchString(pathToken)
  20. }
  21. func removeCustomVerb(str string) string {
  22. return customVerbReg.ReplaceAllString(str, "")
  23. }