newConstraint creates a Constraint with the given handler and data, calling Analyze() if the handler implements ConstraintAnalyzer. rawName is the constraint name as it appeared in the route pattern (e.g. "minlen").
(handler ConstraintHandler, rawName string, args []string)
| 176 | // calling Analyze() if the handler implements ConstraintAnalyzer. |
| 177 | // rawName is the constraint name as it appeared in the route pattern (e.g. "minlen"). |
| 178 | func newConstraint(handler ConstraintHandler, rawName string, args []string) *Constraint { |
| 179 | canonical := handler.Name() |
| 180 | c := &Constraint{ |
| 181 | Name: rawName, |
| 182 | ID: constraintNameToID[canonical], |
| 183 | handler: handler, |
| 184 | Data: args, |
| 185 | } |
| 186 | if analyser, ok := handler.(ConstraintAnalyzer); ok { |
| 187 | if typed, err := analyser.Analyze(args); err == nil { |
| 188 | c.typedData = typed |
| 189 | } |
| 190 | } |
| 191 | // Populate RegexCompiler for backward compat when using default engine. |
| 192 | if canonical == ConstraintRegex && len(c.typedData) > 0 { |
| 193 | if re, ok := c.typedData[0].(*regexp.Regexp); ok { |
| 194 | c.RegexCompiler = re |
| 195 | } |
| 196 | } |
| 197 | return c |
| 198 | } |
| 199 | |
| 200 | // matchConstraint validates a parameter against this constraint. |
| 201 | func (c *Constraint) matchConstraint(param string) bool { |
searching dependent graphs…