validate

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ASCII added in v0.23.0

func ASCII(fname, val string, minLen, maxLen int) error

ASCII will validate that the passed value is an ASCII string within the given length values.

func AbsoluteURL

func AbsoluteURL(fname, urlStr string) error

AbsoluteURL will validate that a URL is valid and contains a scheme and host.

func Duration added in v0.24.0

func Duration(fname string, val, min, max time.Duration) error

Duration will ensure a value is between min and max duration (inclusive). A FieldError is returned otherwise.

func Email

func Email(fname, email string) error

Email will validate an email address, returning a FieldError if invalid. Both named and un-named addresses are valid.

func IDName

func IDName(fname, name string) error

IDName will validate a ASCII name/identifier to ensure it is between 2 and 64 characters, starts with a letter, contains only letters, numbers, and spaces `-`, `_` or `'`.

If invalid, a FieldError with the given field name is returned.

func JMESPath added in v0.26.0

func JMESPath(fname, expression string) error

JMESPath will validate a JMESPath expression.

func LabelKey

func LabelKey(fname, body string) error

LabelKey will validate a label key field to ensure it follows a particular format.

A label key consists of a prefix (lowercase alphanumeric /w hyphens -- domain name rules) followed by a `/` and a suffix consisting of alphanumeric characters and hyphens. The entire key may not exceed 255 characters.

func LabelValue

func LabelValue(fname, body string) error

LabelValue will validate a label value field to ensure it consists of only printable characters as defined by Go. https://golang.org/pkg/unicode/#IsPrint It must be between 3 and 255 characters. If invalid, a FieldError with the given field name is returned.

func Many

func Many(errs ...error) error

Many will take multiple input error values, filter out nils and flatten any nested MultiFieldErrors.

If a given error is not a FieldError, or MultiFieldError it is returned immediately.

If all errs are nil, nil is returned. If only one error is present, it is returned.

func ManyUUID

func ManyUUID(fname string, ids []string, max int) error

ManyUUID will validate a slice of strings, checking each with the UUID validator.

func Name

func Name(fname, name string) error

Name will validate a unicode name to ensure it is between 1 and upperLimit runes, and only consists of printable unicode characters.

If invalid, a FieldError with the given field name is returned.

func NullUUID

func NullUUID(fname string, u sql.NullString) error

NullUUID will validate a UUID, unless Null. It returns a FieldError if invalid.

func OAuthScope added in v0.26.0

func OAuthScope(fname, val string, required ...string) error

OAuthScope is a valid OAuth 2.0 Scope parameter, optionally specifying a list of required scopes.

Requirements based on section 3.3 of RFC6749 https://tools.ietf.org/html/rfc6749#section-3.3

func OneOf

func OneOf(fname string, value interface{}, options ...interface{}) error

OneOf will check that value is one of the provided options.

func Phone

func Phone(fname, phone string) error

Phone will validate a phone number, returning a FieldError if invalid.

func Range

func Range(fname string, val, min, max int) error

Range will ensure a value is between min and max (inclusive). A FieldError is returned otherwise.

func RequiredText

func RequiredText(fname, body string, min, max int) error

RequiredText works like Text, but does not allow it to be blank, unless min is set to 0.

func SanitizeEmail

func SanitizeEmail(email string) string

SanitizeEmail will try to parse the email field and then return lower-case address portion or an empty string if parse failed.

func SanitizeName

func SanitizeName(name string) string

SanitizeName will remove all invalid characters and return a valid name (as defined by ValidateName) or an empty string.

It is used in cases where the input is not provided by a user, and should be used as-is if possible. An example would be importing a user profile from GitHub.

If longer than upperLimit, the extra characters are dropped.

func SanitizeText

func SanitizeText(body string, maxLen int) string

SanitizeText will sanitize a text body so that it passes the Text validation.

func Search(fname, body string) error

Search will validate a search body. It ensures that the field consists of valid unicode code-points, and does not exceed max of 255 characters. If body is empty, the input is considered valid.

func SubjectID

func SubjectID(fname, body string) error

SubjectID will validate a given OIDC subject ID. It ensures that the field consists of valid ASCII characters, is not empty and does not exceed max characters. As per http://openid.net/specs/openid-connect-core-1_0.html#IDToken For sub : It MUST NOT exceed 255 ASCII characters in length.

func Text

func Text(fname, body string, min, max int) error

Text will validate a text body. It ensures that the field consists of valid unicode code-points, has at least min characters and does not exceed max characters, and that it doesn't begin or end with space.

If body is empty, the input is considered valid, regardless of min value.

func URL

func URL(fname, urlStr string) error

URL will validate a URL, returning a FieldError if invalid.

func UUID

func UUID(fname, u string) error

UUID will validate a UUID, returning a FieldError if invalid.

func UserName

func UserName(fname, name string) error

UserName will validate a username to ensure it is between 3 and 24 characters, and only contains lower-case ASCII letters and numbers.

Types

This section is empty.

Jump to

Keyboard shortcuts

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