validate

package
v0.0.0-...-5352646 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package validate implements validation functions, usually used RPC message validation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(fields ...error) error

All returns an error if one of the passed fields is invalid.

func Email

func Email(v interface{}) error

Email checks whether the input value is a valid email or not.

func Empty

func Empty(v interface{}) error

Empty returns error if v is set. It is meant to be used as the first validator function passed as argument to Field. It uses IsZero, if v implements IsZeroer interface.

func FieldMaskPaths

func FieldMaskPaths(fm *types.FieldMask) error

FieldMaskPaths performs a basic sanity check on the allowed characters for valid fieldmask paths. Paths of a FieldMask may only contain lowercase letters, numbers, dots, underscores and must be between 2 and 256 characters in length.

func In

func In(slice interface{}) validateFn

In checks whether:

  • an element is contained in an array or slice
  • a slice is a subset of other slice

func MinLength

func MinLength(length int) validateFn

MinLength checks whether the input value has a minimum length in the following cases:

  • For strings checks the length
  • For slices checks that aren't nil and its length
  • For other types returns error

func NotRequired

func NotRequired(v interface{}) error

NotRequired returns an error, used internally in Field, if v is zero. It is meant to be used as the first validator function passed as argument to Field. It uses IsZero, if v implements IsZeroer interface.

func Password

func Password(v interface{}) error

Password checks whether the input value is a string and is at least 8 characters long.

func Required

func Required(v interface{}) error

Required returns error if v is empty. It is meant to be used as the first validator function passed as argument to Field. It uses IsZero, if v implements IsZeroer interface.

Types

type IsZeroer

type IsZeroer interface {
	IsZero() bool
}

IsZeroer is an interface, which reports whether it represents a zero value.

type ValidationField

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

ValidationField implements error, and represents whether a field is valid or invalid.

func Field

func Field(v interface{}, verifiers ...func(interface{}) error) (vf *ValidationField)

Field verifies whether a field is valid, and returns an error if it is invalid.

func (*ValidationField) DescribeFieldName

func (vf *ValidationField) DescribeFieldName(name string) error

DescribeFieldName attaches the name of a field to the validation of a field, and returns it in an error format.

Jump to

Keyboard shortcuts

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