validation

package
v0.0.0-...-5f0f127 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2019 License: Apache-2.0 Imports: 3 Imported by: 1

README

go-validation

Overview

go-validation provides struct validation utilities. See validation_test.go for sample usage.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEmail

func IsEmail(str string) bool

IsEmail returns true if the given email address is valid, false otherwise

func IsEmpty

func IsEmpty(s interface{}) bool

IsEmpty returns true if the given interface is empty, false otherwise

func IsURL

func IsURL(str string) bool

IsURL returns true if the given url is valid, false otherwise

func Matches

func Matches(str, pattern string) bool

Matches returns true if the given string matches the given pattern, false otherwise

Types

type Error

type Error struct {
	FieldName  string
	FieldValue interface{}
	// contains filtered or unexported fields
}

Error represents a validation error

func InvalidEmail

func InvalidEmail(fieldName, fieldValue string) *Error

InvalidEmail returns an invalid validation error for the given field name and value

func InvalidEmpty

func InvalidEmpty(fieldName string) *Error

InvalidEmpty returns an empty validation Error for the given field name

func InvalidURL

func InvalidURL(fieldName, fieldValue string) *Error

InvalidURL returns an invalid validation error for the given field name and value

func (*Error) Error

func (e *Error) Error() string

Error returns the string representation of the error

func (*Error) MsgForCode

func (e *Error) MsgForCode() string

MsgForCode returns a human readable message for the given ErrorKind. The message may optionally include the given field value in the message.

type ErrorKind

type ErrorKind int

ErrorKind represents a validation error type

const (
	// ErrorGeneral represents a catchall validation error. That is,
	// an error that does not match any ErrorKind.
	ErrorGeneral ErrorKind = iota
	// ErrorEmpty represents an empty field validation error.
	ErrorEmpty
	// ErrorInvalidEmail represents an invalid email validation error.
	ErrorInvalidEmail
	// ErrorInvalidURL represents an invalid url validation error.
	ErrorInvalidURL
)

ErrorKind enumeration

type Errors

type Errors []*Error

Errors is a list of validation Errors

type Validater

type Validater interface {
	Validate() (bool, Errors)
}

Validater has a single function Validate, which can be used to determine if the interface implementation is valid. Validate should return true if the implementation passes validation, false otherwise. If invalid, a list of one or more validation Errors should be returned.

Jump to

Keyboard shortcuts

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