validation

package
v1.2.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 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 NewDuplicateError

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

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

func NewForbiddenError

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

NewForbiddenError 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 NewInternalError

func NewInternalError(field string, err error) *Error

NewInternalError returns a *Error indicating "internal error". This is used to signal that an error was found that was not directly related to user input. The err argument must be non-nil.

func NewInvalidError

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

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

func NewNotFoundError

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

NewNotFoundError 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 NewNotSupportedError

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

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

func NewRequiredError

func NewRequiredError(field string) *Error

NewRequiredError 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 NewTooLongError

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

NewTooLongError returns a *Error indicating "too long". This is used to report that the given value is too long. This is similar to NewInvalidError, 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.

func (ErrorList) ToAggregate

func (list ErrorList) ToAggregate() utilerrors.Aggregate

ToAggregate converts the ErrorList into an errors.Aggregate.

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 NewNotFoundError.
	ErrorTypeNotFound ErrorType = "FieldValueNotFound"
	// ErrorTypeRequired is used to report required values that are not
	// provided (e.g. empty strings, null values, or empty arrays).  See
	// NewRequiredError.
	ErrorTypeRequired ErrorType = "FieldValueRequired"
	// ErrorTypeDuplicate is used to report collisions of values that must be
	// unique (e.g. unique IDs).  See NewDuplicateError.
	ErrorTypeDuplicate ErrorType = "FieldValueDuplicate"
	// ErrorTypeInvalid is used to report malformed values (e.g. failed regex
	// match, too long, out of bounds).  See NewInvalidError.
	ErrorTypeInvalid ErrorType = "FieldValueInvalid"
	// ErrorTypeNotSupported is used to report unknown values for enumerated
	// fields (e.g. a list of valid values).  See NewNotSupportedError.
	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
	// NewForbiddenError.
	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 NewTooLongError.
	ErrorTypeTooLong ErrorType = "FieldValueTooLong"
	// ErrorTypeInternal is used to report other errors that are not related
	// to user input.
	ErrorTypeInternal ErrorType = "InternalError"
)

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