@@ -69,7 +69,7 @@ const (
6969)
7070
7171// TypeConstraint parameter constraint types
72- type TypeConstraint int16
72+ type TypeConstraint uint16
7373
7474// Constraint describes the validation rules that apply to a dynamic route
7575// segment when matching incoming requests.
@@ -95,7 +95,7 @@ type CustomConstraint interface {
9595}
9696
9797const (
98- noConstraint TypeConstraint = iota + 1
98+ noConstraint TypeConstraint = 1 << iota
9999 intConstraint
100100 boolConstraint
101101 floatConstraint
@@ -112,6 +112,11 @@ const (
112112 regexConstraint
113113)
114114
115+ const (
116+ needOneData = minLenConstraint | maxLenConstraint | lenConstraint | minConstraint | maxConstraint | datetimeConstraint | regexConstraint
117+ needTwoData = betweenLenConstraint | rangeConstraint
118+ )
119+
115120// list of possible parameter and segment delimiter
116121var (
117122 // slash has a special role, unlike the other parameters it must not be interpreted as a parameter
@@ -705,18 +710,13 @@ func (c *Constraint) CheckConstraint(param string) bool {
705710 num int
706711 )
707712
708- // Validate constraint has required data using switch instead of slice allocation
709- switch c .ID {
710- case minLenConstraint , maxLenConstraint , lenConstraint , minConstraint , maxConstraint , datetimeConstraint , regexConstraint :
711- if len (c .Data ) == 0 {
712- return false
713- }
714- case betweenLenConstraint , rangeConstraint :
715- if len (c .Data ) < 2 {
716- return false
717- }
718- default :
719- // Other constraints don't require data validation
713+ // Validate constraint has required data
714+ if c .ID & needOneData != 0 && len (c .Data ) == 0 {
715+ return false
716+ }
717+
718+ if c .ID & needTwoData != 0 && len (c .Data ) < 2 {
719+ return false
720720 }
721721
722722 switch c .ID {
0 commit comments