mirror of
https://github.com/kataras/iris.git
synced 2025-01-26 03:56:34 +01:00
126c4de29b
1. Fix index, including both start and end. So Literal[start:end+1] will be a valid part. 2. Replace any with string, add file param type 3. Start of making the evaluator, starting with regexp for param types (these expression can be changed or/and overriden by user later on) Former-commit-id: ab95265f953dadbf84170b543e1ff8840f9c4a14
28 lines
529 B
Go
28 lines
529 B
Go
package evaluator
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
)
|
|
|
|
// final evaluator signature for both param types and param funcs
|
|
type ParamEvaluator func(paramValue string) bool
|
|
|
|
func NewParamEvaluatorFromRegexp(expr string) (ParamEvaluator, error) {
|
|
if expr == "" {
|
|
return nil, fmt.Errorf("empty regex expression")
|
|
}
|
|
|
|
// add the last $ if missing (and not wildcard(?))
|
|
if i := expr[len(expr)-1]; i != '$' && i != '*' {
|
|
expr += "$"
|
|
}
|
|
|
|
r, err := regexp.Compile(expr)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return r.MatchString, nil
|
|
}
|