MCPcopy
hub / github.com/gofiber/fiber / newConstraint

Function newConstraint

constraint.go:178–198  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

176// calling Analyze() if the handler implements ConstraintAnalyzer.
177// rawName is the constraint name as it appeared in the route pattern (e.g. "minlen").
178func 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.
201func (c *Constraint) matchConstraint(param string) bool {

Calls 2

NameMethod · 0.65
AnalyzeMethod · 0.65

Used in the wild real call sites across dependent graphs

searching dependent graphs…