Help us shape the future of Go! Take the 2026 Go Developer Survey

validation

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IntegerValidator

func IntegerValidator(ans interface{}) error

IntegerValidator validates that the provided object can be properly converted to an int value

func KeyEqValFormatValidator

func KeyEqValFormatValidator(portsStr interface{}) error

KeyEqValFormatValidator ensures that all the parts of the input follow the key=value format examples of valid input are: NAME=JANE PORT=8080,PATH=/health

func NameValidator

func NameValidator(name interface{}) error

NameValidator provides a Validator view of the ValidateName function.

func NilValidator

func NilValidator(interface{}) error

NilValidator always validates

func NonNegativeValidator

func NonNegativeValidator(arg interface{}) error

NonNegativeValidator validates whether the given value is not negative or not

func PathValidator

func PathValidator(path interface{}) error

PathValidator validates whether the given path exists on the file system

func PortsValidator

func PortsValidator(portsStr interface{}) error

PortsValidator validates whether all the parts of the input are valid port declarations examples of valid input are: 8080 8080, 9090/udp 8080/tcp, 9090/udp

func ValidateHost

func ValidateHost(host string) error

ValidateHost validates that the provided host is a valid subdomain according to DNS (RFC 1123) rules

func ValidateName

func ValidateName(name string) error

ValidateName will do validation of application & component names according to DNS (RFC 1123) rules Criteria for valid name in kubernetes: https://github.com/kubernetes/community/blob/master/contributors/design-proposals/architecture/identifiers.md

Types

type Validatable

type Validatable struct {
	// Required indicates whether this Validatable is a required value in the context it's supposed to be used
	Required bool `json:"required,omitempty"`
	// Type specifies the type of values this Validatable accepts so that some validation can be performed based on it
	Type string `json:"type"`
	// AdditionalValidators allows users to specify validators (in addition to default ones) to validate this Validatable's value
	AdditionalValidators []Validator `json:"-"`
}

Validatable represents a common ancestor for validatable parameters

func (Validatable) AsValidatable

func (v Validatable) AsValidatable() Validatable

AsValidatable allows avoiding type casts in client code

type Validator

type Validator func(interface{}) error

Validator is a function that validates that the provided interface conforms to expectations or return an error

func GetValidatorFor

func GetValidatorFor(prop Validatable) Validator

GetValidatorFor retrieves a validator for the specified validatable, first validating its required state, then its value based on type then any additional validators in the order specified by Validatable.AdditionalValidators

Jump to

Keyboard shortcuts

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