vikunja-api/vendor/github.com/labstack/echo/middleware/middleware.go

39 lines
849 B
Go
Raw Normal View History

2018-06-10 11:11:41 +02:00
package middleware
2018-11-03 16:05:45 +01:00
import (
"regexp"
"strconv"
"strings"
"github.com/labstack/echo"
)
2018-06-10 11:11:41 +02:00
type (
// Skipper defines a function to skip middleware. Returning true skips processing
// the middleware.
2019-03-24 10:13:40 +01:00
Skipper func(echo.Context) bool
// BeforeFunc defines a function which is executed just before the middleware.
BeforeFunc func(echo.Context)
2018-06-10 11:11:41 +02:00
)
2018-11-03 16:05:45 +01:00
func captureTokens(pattern *regexp.Regexp, input string) *strings.Replacer {
groups := pattern.FindAllStringSubmatch(input, -1)
if groups == nil {
return nil
}
values := groups[0][1:]
replace := make([]string, 2*len(values))
for i, v := range values {
j := 2 * i
replace[j] = "$" + strconv.Itoa(i+1)
replace[j+1] = v
}
return strings.NewReplacer(replace...)
}
2018-06-10 11:11:41 +02:00
// DefaultSkipper returns false which processes the middleware.
func DefaultSkipper(echo.Context) bool {
return false
}