2016-07-27 18:34:44 +02:00
|
|
|
package middleware
|
|
|
|
|
2017-12-28 01:14:44 +02:00
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/labstack/echo"
|
|
|
|
)
|
2016-07-27 18:34:44 +02:00
|
|
|
|
|
|
|
type (
|
|
|
|
// Skipper defines a function to skip middleware. Returning true skips processing
|
|
|
|
// the middleware.
|
|
|
|
Skipper func(c echo.Context) bool
|
|
|
|
)
|
|
|
|
|
2017-12-28 01:14:44 +02: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...)
|
|
|
|
}
|
|
|
|
|
2017-01-28 21:43:56 +02:00
|
|
|
// DefaultSkipper returns false which processes the middleware.
|
2017-02-19 23:02:10 +02:00
|
|
|
func DefaultSkipper(echo.Context) bool {
|
2016-07-27 18:34:44 +02:00
|
|
|
return false
|
|
|
|
}
|