Documentation ¶
Index ¶
- func ASCII(fname, val string, minLen, maxLen int) error
- func AbsoluteURL(fname, urlStr string) error
- func Duration(fname string, val, min, max time.Duration) error
- func Email(fname, email string) error
- func IDName(fname, name string) error
- func JMESPath(fname, expression string) error
- func LabelKey(fname, body string) error
- func LabelValue(fname, body string) error
- func Many(errs ...error) error
- func ManyUUID(fname string, ids []string, max int) error
- func Name(fname, name string) error
- func NullUUID(fname string, u sql.NullString) error
- func OAuthScope(fname, val string, required ...string) error
- func OneOf(fname string, value interface{}, options ...interface{}) error
- func Phone(fname, phone string) error
- func Range(fname string, val, min, max int) error
- func RequiredText(fname, body string, min, max int) error
- func SanitizeEmail(email string) string
- func SanitizeName(name string) string
- func SanitizeText(body string, maxLen int) string
- func Search(fname, body string) error
- func SubjectID(fname, body string) error
- func Text(fname, body string, min, max int) error
- func URL(fname, urlStr string) error
- func UUID(fname, u string) error
- func UserName(fname, name string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ASCII ¶ added in v0.23.0
ASCII will validate that the passed value is an ASCII string within the given length values.
func AbsoluteURL ¶
AbsoluteURL will validate that a URL is valid and contains a scheme and host.
func Duration ¶ added in v0.24.0
Duration will ensure a value is between min and max duration (inclusive). A FieldError is returned otherwise.
func Email ¶
Email will validate an email address, returning a FieldError if invalid. Both named and un-named addresses are valid.
func IDName ¶
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 LabelKey ¶
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 ¶
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 ¶
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 Name ¶
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
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 Range ¶
Range will ensure a value is between min and max (inclusive). A FieldError is returned otherwise.
func RequiredText ¶
RequiredText works like Text, but does not allow it to be blank, unless min is set to 0.
func SanitizeEmail ¶
SanitizeEmail will try to parse the email field and then return lower-case address portion or an empty string if parse failed.
func SanitizeName ¶
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 ¶
SanitizeText will sanitize a text body so that it passes the Text validation.
func Search ¶ added in v0.23.0
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 ¶
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 ¶
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.
Types ¶
This section is empty.