Make IsDNS952Label return error strings

This commit is contained in:
Tim Hockin
2015-12-19 21:02:12 -08:00
parent 5862a60ae7
commit 54a3efb364
4 changed files with 17 additions and 12 deletions

View File

@@ -128,8 +128,15 @@ var dns952LabelRegexp = regexp.MustCompile("^" + DNS952LabelFmt + "$")
// IsDNS952Label tests for a string that conforms to the definition of a label in
// DNS (RFC 952).
func IsDNS952Label(value string) bool {
return len(value) <= DNS952LabelMaxLength && dns952LabelRegexp.MatchString(value)
func IsDNS952Label(value string) []string {
var errs []string
if len(value) > DNS952LabelMaxLength {
errs = append(errs, MaxLenError(DNS952LabelMaxLength))
}
if !dns952LabelRegexp.MatchString(value) {
errs = append(errs, RegexError(DNS952LabelFmt, "my-name", "abc-123"))
}
return errs
}
const CIdentifierFmt string = "[A-Za-z_][A-Za-z0-9_]*"