validation

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2016 License: Apache-2.0, Apache-2.0 Imports: 8 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 *FieldPath, 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 *FieldPath, 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 *FieldPath, 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 *FieldPath, 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 *FieldPath, 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 *FieldPath, 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 *FieldPath) *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 *FieldPath, 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) 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.

type FieldPath

type FieldPath struct {
	// contains filtered or unexported fields
}

FieldPath represents the path from some root to a particular field.

func NewFieldPath

func NewFieldPath(name string, moreNames ...string) *FieldPath

NewFieldPath creates a root FieldPath object.

func (*FieldPath) Child

func (fp *FieldPath) Child(name string, moreNames ...string) *FieldPath

Child creates a new FieldPath that is a child of the method receiver.

func (*FieldPath) Index

func (fp *FieldPath) Index(index int) *FieldPath

Index indicates that the previous FieldPath is to be subscripted by an int. This sets the same underlying value as Key.

func (*FieldPath) Key

func (fp *FieldPath) Key(key string) *FieldPath

Key indicates that the previous FieldPath is to be subscripted by a string. This sets the same underlying value as Index.

func (*FieldPath) Root

func (fp *FieldPath) Root() *FieldPath

Root returns the root element of this FieldPath.

func (*FieldPath) String

func (fp *FieldPath) String() string

String produces a string representation of the FieldPath.

Jump to

Keyboard shortcuts

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