validation

package
v0.11.1-0...-a229925 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2015 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const CIdentifierFmt string = "[A-Za-z_][A-Za-z0-9_]*"
View Source
const DNS1123LabelFmt string = "[a-z0-9]([-a-z0-9]*[a-z0-9])?"
View Source
const DNS1123LabelMaxLength int = 63
View Source
const DNS1123SubdomainFmt string = DNS1123LabelFmt + "(\\." + DNS1123LabelFmt + ")*"
View Source
const DNS1123SubdomainMaxLength int = 253
View Source
const DNS952LabelFmt string = "[a-z]([-a-z0-9]*[a-z0-9])?"
View Source
const DNS952LabelMaxLength int = 24
View Source
const IdentifierNoHyphensBeginEndFmt string = "[a-z0-9]([a-z0-9-]*[a-z0-9])*"
View Source
const LabelValueFmt string = "(" + QualifiedNameFmt + ")?"
View Source
const LabelValueMaxLength int = 63
View Source
const QualifiedNameFmt string = "(" + qnameCharFmt + qnameExtCharFmt + "*)?" + qnameCharFmt
View Source
const QualifiedNameMaxLength int = 63

Variables

This section is empty.

Functions

func IsCIdentifier

func IsCIdentifier(value string) bool

IsCIdentifier tests for a string that conforms the definition of an identifier in C. This checks the format, but not the length.

func IsDNS1123Label

func IsDNS1123Label(value string) bool

IsDNS1123Label tests for a string that conforms to the definition of a label in DNS (RFC 1123).

func IsDNS1123Subdomain

func IsDNS1123Subdomain(value string) bool

IsDNS1123Subdomain tests for a string that conforms to the definition of a subdomain in DNS (RFC 1123).

func IsDNS952Label

func IsDNS952Label(value string) bool

IsDNS952Label tests for a string that conforms to the definition of a label in DNS (RFC 952).

func IsQualifiedName

func IsQualifiedName(value string) bool

func IsValidIPv4

func IsValidIPv4(value string) bool

IsValidIPv4 tests that the argument is a valid IPv4 address.

func IsValidLabelValue

func IsValidLabelValue(value string) bool

func IsValidPercent

func IsValidPercent(percent string) bool

func IsValidPortName

func IsValidPortName(port string) bool

IsValidPortName check that the argument is valid syntax. It must be non empty and no more than 15 characters long It must contains at least one letter [a-z] and it must contains only [a-z0-9-]. Hypens ('-') cannot be leading or trailing character of the string and cannot be adjacent to other hyphens. Although RFC 6335 allows upper and lower case characters but case is ignored for comparison purposes: (HTTP and http denote the same service).

func IsValidPortNum

func IsValidPortNum(port int) bool

IsValidPortNum tests that the argument is a valid, non-zero port number.

func NewErrorTypeMatcher

func NewErrorTypeMatcher(t ErrorType) utilerrors.Matcher

NewErrorTypeMatcher returns an errors.Matcher that returns true if the provided error is a Error and has the provided ErrorType.

Types

type Error

type Error struct {
	Type     ErrorType
	Field    string
	BadValue interface{}
	Detail   string
}

Error is an implementation of the 'error' interface, which represents a validation error.

func NewFieldDuplicate

func NewFieldDuplicate(field string, value interface{}) *Error

NewFieldDuplicate returns a *Error indicating "duplicate value". This is used to report collisions of values that must be unique (e.g. names or IDs).

func NewFieldForbidden

func NewFieldForbidden(field string, value interface{}) *Error

NewFieldForbidden returns a *Error indicating "forbidden". This is used to report valid (as per formatting rules) values which would be accepted under some conditions, but which are not permitted by current conditions (e.g. security policy).

func NewFieldInvalid

func NewFieldInvalid(field string, value interface{}, detail string) *Error

NewFieldInvalid returns a *Error indicating "invalid value". This is used to report malformed values (e.g. failed regex match, too long, out of bounds).

func NewFieldNotFound

func NewFieldNotFound(field string, value interface{}) *Error

NewFieldNotFound returns a *Error indicating "value not found". This is used to report failure to find a requested value (e.g. looking up an ID).

func NewFieldNotSupported

func NewFieldNotSupported(field string, value interface{}, validValues []string) *Error

NewFieldNotSupported returns a *Error indicating "unsupported value". This is used to report unknown values for enumerated fields (e.g. a list of valid values).

func NewFieldRequired

func NewFieldRequired(field string) *Error

NewFieldRequired returns a *Error indicating "value required". This is used to report required values that are not provided (e.g. empty strings, null values, or empty arrays).

func NewFieldTooLong

func NewFieldTooLong(field string, value interface{}, maxLength int) *Error

NewFieldTooLong returns a *Error indicating "too long". This is used to report that the given value is too long. This is similar to NewFieldInvalid, but the returned error will not include the too-long value.

func (*Error) Error

func (v *Error) Error() string

Error implements the error interface.

func (*Error) ErrorBody

func (v *Error) ErrorBody() string

ErrorBody returns the error message without the field name. This is useful for building nice-looking higher-level error reporting.

type ErrorList

type ErrorList []error

ErrorList holds a set of errors.

func (ErrorList) Filter

func (list ErrorList) Filter(fns ...utilerrors.Matcher) ErrorList

Filter removes items from the ErrorList that match the provided fns.

func (ErrorList) Prefix

func (list ErrorList) Prefix(prefix string) ErrorList

Prefix adds a prefix to the Field of every Error in the list. Returns the list for convenience.

func (ErrorList) PrefixIndex

func (list ErrorList) PrefixIndex(index int) ErrorList

PrefixIndex adds an index to the Field of every Error in the list. Returns the list for convenience.

type ErrorType

type ErrorType string

ErrorType is a machine readable value providing more detail about why a field is invalid. These values are expected to match 1-1 with CauseType in api/types.go.

const (
	// ErrorTypeNotFound is used to report failure to find a requested value
	// (e.g. looking up an ID).  See NewFieldNotFound.
	ErrorTypeNotFound ErrorType = "FieldValueNotFound"
	// ErrorTypeRequired is used to report required values that are not
	// provided (e.g. empty strings, null values, or empty arrays).  See
	// NewFieldRequired.
	ErrorTypeRequired ErrorType = "FieldValueRequired"
	// ErrorTypeDuplicate is used to report collisions of values that must be
	// unique (e.g. unique IDs).  See NewFieldDuplicate.
	ErrorTypeDuplicate ErrorType = "FieldValueDuplicate"
	// ErrorTypeInvalid is used to report malformed values (e.g. failed regex
	// match, too long, out of bounds).  See NewFieldInvalid.
	ErrorTypeInvalid ErrorType = "FieldValueInvalid"
	// ErrorTypeNotSupported is used to report unknown values for enumerated
	// fields (e.g. a list of valid values).  See NewFieldNotSupported.
	ErrorTypeNotSupported ErrorType = "FieldValueNotSupported"
	// ErrorTypeForbidden is used to report valid (as per formatting rules)
	// values which would be accepted under some conditions, but which are not
	// permitted by the current conditions (such as security policy).  See
	// NewFieldForbidden.
	ErrorTypeForbidden ErrorType = "FieldValueForbidden"
	// ErrorTypeTooLong is used to report that the given value is too long.
	// This is similar to ErrorTypeInvalid, but the error will not include the
	// too-long value.  See NewFieldTooLong.
	ErrorTypeTooLong ErrorType = "FieldValueTooLong"
)

TODO: These values are duplicated in api/types.go, but there's a circular dep. Fix it.

func (ErrorType) String

func (t ErrorType) String() string

String converts a ErrorType into its corresponding canonical error message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL