Cleanup of validation.go

This commit is contained in:
gmarek
2015-03-11 15:57:19 +01:00
parent faab509a23
commit a3b137ce8e
9 changed files with 62 additions and 78 deletions

View File

@@ -20,16 +20,15 @@ import (
"regexp"
)
const kubeChar string = "[A-Za-z0-9]"
const extendedKubeChar string = "[-A-Za-z0-9_.]"
const qualifiedToken string = "(" + kubeChar + extendedKubeChar + "*)?" + kubeChar
const qnameCharFmt string = "[A-Za-z0-9]"
const qnameExtCharFmt string = "[-A-Za-z0-9_.]"
const qnameTokenFmt string = "(" + qnameCharFmt + qnameExtCharFmt + "*)?" + qnameCharFmt
const LabelValueFmt string = "((" + kubeChar + extendedKubeChar + "*)?" + kubeChar + ")?"
const LabelValueFmt string = "(" + qnameTokenFmt + ")?"
const LabelValueMaxLength int = 63
var labelValueRegexp = regexp.MustCompile("^" + LabelValueFmt + "$")
const LabelValueMaxLength int = 63
func IsValidLabelValue(value string) bool {
return (len(value) <= LabelValueMaxLength && labelValueRegexp.MatchString(value))
}
@@ -39,20 +38,20 @@ func IsValidAnnotationValue(value string) bool {
return true
}
const QualifiedNameFmt string = "(" + qualifiedToken + "/)?" + qualifiedToken
const QualifiedNameFmt string = "(" + qnameTokenFmt + "/)?" + qnameTokenFmt
const QualifiedNameMaxLength int = 253
var qualifiedNameRegexp = regexp.MustCompile("^" + QualifiedNameFmt + "$")
func IsQualifiedName(value string) bool {
return (len(value) <= DNS1123SubdomainMaxLength && qualifiedNameRegexp.MatchString(value))
return (len(value) <= QualifiedNameMaxLength && qualifiedNameRegexp.MatchString(value))
}
const DNS1123LabelFmt string = "[a-z0-9]([-a-z0-9]*[a-z0-9])?"
const DNS1123LabelMaxLength int = 63
var dns1123LabelRegexp = regexp.MustCompile("^" + DNS1123LabelFmt + "$")
const DNS1123LabelMaxLength int = 63
// IsDNS1123Label tests for a string that conforms to the definition of a label in
// DNS (RFC 1123).
func IsDNS1123Label(value string) bool {
@@ -60,35 +59,21 @@ func IsDNS1123Label(value string) bool {
}
const DNS1123SubdomainFmt string = DNS1123LabelFmt + "(\\." + DNS1123LabelFmt + ")*"
const DNS1123SubdomainMaxLength int = 253
var dns1123SubdomainRegexp = regexp.MustCompile("^" + DNS1123SubdomainFmt + "$")
const DNS1123SubdomainMaxLength int = 253
// IsDNS1123Subdomain tests for a string that conforms to the definition of a
// subdomain in DNS (RFC 1123).
func IsDNS1123Subdomain(value string) bool {
return len(value) <= DNS1123SubdomainMaxLength && dns1123SubdomainRegexp.MatchString(value)
}
// IsDNSLabel tests for a string that conforms to the definition of a label in
// DNS (RFC 1123).
func IsDNSLabel(value string) bool {
return IsDNS1123Label(value)
}
// IsDNSSubdomain tests for a string that conforms to the definition of a
// subdomain in DNS (RFC 1123).
func IsDNSSubdomain(value string) bool {
return IsDNS1123Subdomain(value)
}
const DNS952LabelFmt string = "[a-z]([-a-z0-9]*[a-z0-9])?"
const DNS952LabelMaxLength int = 24
var dns952LabelRegexp = regexp.MustCompile("^" + DNS952LabelFmt + "$")
const DNS952LabelMaxLength int = 24
// IsDNS952Label tests for a string that conforms to the definition of a label in
// DNS (RFC 952).
func IsDNS952Label(value string) bool {