mirror of
https://github.com/webx-top/echo
synced 2021-12-20 05:52:35 +00:00
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
/*
|
|
|
|
Copyright 2016 Wenhui Shen <www.webx.top>
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
package echo
|
|
|
|
import (
|
|
"regexp"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
type (
|
|
// Skipper defines a function to skip middleware. Returning true skips processing
|
|
// the middleware.
|
|
Skipper func(c Context) bool
|
|
)
|
|
|
|
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...)
|
|
}
|
|
|
|
// DefaultSkipper returns false which processes the middleware.
|
|
func DefaultSkipper(c Context) bool {
|
|
return false
|
|
}
|