joi

package
v0.0.0-...-34d5e10 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAnyType      = NewError("interface", "Value of wrong data type")
	ErrAnyRequired  = NewError("interface", "Value is required")
	ErrAnyForbidden = NewError("interface", "Value is forbidden")
	ErrAnyZero      = NewError("interface", "Value should be zero")
	ErrAnyNonZero   = NewError("interface", "Value should be non-zero")
	ErrAnyAllow     = NewError("interface", "Value is not matching allowed values")
	ErrAnyDisallow  = NewError("interface", "Value is matching disallowed values")
)

AnySchema Error definitions

View Source
var (
	ErrIntMin      = NewError("int", "Value is smaller")
	ErrIntMax      = NewError("int", "Value is bigger")
	ErrIntPositive = NewError("int", "Value is not positive")
	ErrIntNegative = NewError("int", "Value is not negative")
	ErrIntGreater  = NewError("int", "Value is not greater")
	ErrIntLess     = NewError("int", "Value is not less")
	ErrIntMultiple = NewError("int", "Value is not matching multiple")
)

StringSchema Error definitions

View Source
var (
	ErrSliceMin    = NewError("slice", "Slice is smaller than min")
	ErrSliceMax    = NewError("slice", "Slice is larger than max")
	ErrSliceLength = NewError("slice", "Slice is not matching length")
)

SliceSchema Error definitions

View Source
var (
	ErrStringMin          = NewError("string", "Value is smaller")
	ErrStringMax          = NewError("string", "Value is bigger")
	ErrStringLength       = NewError("string", "Value is out of length")
	ErrStringUpperCase    = NewError("string", "Value is not uppercase")
	ErrStringLowerCase    = NewError("string", "Value is not lowercase")
	ErrStringRegex        = NewError("string", "Value is not matching regex")
	ErrStringRegexCompile = NewError("string", "Could not compile regex")
	ErrStringCreditCard   = NewError("string", "Value is not matching creditcard")
	ErrStringBase64       = NewError("string", "Value is not matching base64")
	ErrStringHex          = NewError("string", "Value is not matching hex")
	ErrStringEmail        = NewError("string", "Value is not matching email")
)

StringSchema Error definitions

View Source
var (
	ErrSchemaNil = errors.New("Schema cannot be nil")
)

Error definitions

Functions

func BoolToPointer

func BoolToPointer(value bool) *bool

BoolToPointer converts a bool to *bool

func IsSet

func IsSet(pointer interface{}) bool

IsSet returns true if pointer is not nil

func Validate

func Validate(value interface{}, schema Schema) error

Validate ...

Types

type AnySchema

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

AnySchema defines the struct properties

func Any

func Any() *AnySchema

Any ...

func NewAnySchema

func NewAnySchema() *AnySchema

NewAnySchema creates a new AnySchema object

func (*AnySchema) Allow

func (s *AnySchema) Allow(values ...interface{}) *AnySchema

Allow whitelists a value

func (*AnySchema) Description

func (s *AnySchema) Description(description string) *AnySchema

Description stores a description

func (*AnySchema) Disallow

func (s *AnySchema) Disallow(values ...interface{}) *AnySchema

Disallow blacklists a value

func (*AnySchema) Forbidden

func (s *AnySchema) Forbidden() *AnySchema

Forbidden marks a key as forbidden which will not allow any value except nil

func (*AnySchema) Kind

func (s *AnySchema) Kind() string

Kind gets the type of the schema

func (*AnySchema) NonZero

func (s *AnySchema) NonZero() *AnySchema

NonZero marks a key as required to be a non-zero value

func (*AnySchema) Required

func (s *AnySchema) Required() *AnySchema

Required marks a key as required which will not allow nil as value

func (*AnySchema) Root

func (s *AnySchema) Root() Schema

Root stores the root type for validation

func (*AnySchema) Transform

func (s *AnySchema) Transform(stage TransformStage, f TransformFunc) *AnySchema

Transform allows to run custom tranformation functions

func (*AnySchema) Validate

func (s *AnySchema) Validate(value interface{}) error

Validate runs validation for AnySchema

func (*AnySchema) Zero

func (s *AnySchema) Zero() *AnySchema

Zero marks a key as required to be a zero value

type BoolSchema

type BoolSchema struct {
	AnySchema
}

BoolSchema ...

func Bool

func Bool() *BoolSchema

Bool ...

func NewBoolSchema

func NewBoolSchema() *BoolSchema

NewBoolSchema ...

func (*BoolSchema) Kind

func (s *BoolSchema) Kind() string

Kind ...

func (*BoolSchema) Validate

func (s *BoolSchema) Validate(value interface{}) error

Validate ...

type EmailOptions

type EmailOptions struct {
	SMTPLookup bool
}

EmailOptions ...

type Error

type Error struct {
	Schema   string `json:"schema"`
	ErrorMsg string `json:"error"`
}

Error ...

func NewError

func NewError(schema, errorMsg string) *Error

NewError ...

func (*Error) Error

func (e *Error) Error() string

Error ...

type IntSchema

type IntSchema struct {
	AnySchema
	// contains filtered or unexported fields
}

IntSchema ...

func Int

func Int() *IntSchema

Int ...

func NewIntSchema

func NewIntSchema() *IntSchema

NewIntSchema ...

func (*IntSchema) Greater

func (s *IntSchema) Greater(limit int64) *IntSchema

Greater ...

func (*IntSchema) Kind

func (s *IntSchema) Kind() string

Kind ...

func (*IntSchema) Less

func (s *IntSchema) Less(limit int64) *IntSchema

Less ...

func (*IntSchema) Max

func (s *IntSchema) Max(max int64) *IntSchema

Max ...

func (*IntSchema) Min

func (s *IntSchema) Min(min int64) *IntSchema

Min ...

func (*IntSchema) Multiple

func (s *IntSchema) Multiple(base int64) *IntSchema

Multiple ...

func (*IntSchema) Negative

func (s *IntSchema) Negative() *IntSchema

Negative ...

func (*IntSchema) Positive

func (s *IntSchema) Positive() *IntSchema

Positive ...

func (*IntSchema) Validate

func (s *IntSchema) Validate(value interface{}) error

Validate ...

type Schema

type Schema interface {
	Kind() string
	Root() Schema
	Validate(value interface{}) error
}

Schema ...

type SliceSchema

type SliceSchema struct {
	AnySchema
	// contains filtered or unexported fields
}

SliceSchema ...

func NewSliceSchema

func NewSliceSchema() *SliceSchema

NewSliceSchema ...

func Slice

func Slice() *SliceSchema

Slice ...

func (*SliceSchema) Items

func (s *SliceSchema) Items(schema Schema) *SliceSchema

Items ...

func (*SliceSchema) Kind

func (s *SliceSchema) Kind() string

Kind ...

func (*SliceSchema) Length

func (s *SliceSchema) Length(length int) *SliceSchema

Length ...

func (*SliceSchema) Max

func (s *SliceSchema) Max(max int) *SliceSchema

Max ...

func (*SliceSchema) Min

func (s *SliceSchema) Min(min int) *SliceSchema

Min ...

func (*SliceSchema) Validate

func (s *SliceSchema) Validate(value interface{}) error

Validate ...

type StringSchema

type StringSchema struct {
	AnySchema
	// contains filtered or unexported fields
}

StringSchema ...

func NewStringSchema

func NewStringSchema() *StringSchema

NewStringSchema ...

func String

func String() *StringSchema

String ...

func (*StringSchema) Base64

func (s *StringSchema) Base64() *StringSchema

Base64 ...

func (*StringSchema) CreditCard

func (s *StringSchema) CreditCard() *StringSchema

CreditCard ...

func (*StringSchema) Email

func (s *StringSchema) Email(options *EmailOptions) *StringSchema

Email ...

func (*StringSchema) Hex

func (s *StringSchema) Hex() *StringSchema

Hex ...

func (*StringSchema) Kind

func (s *StringSchema) Kind() string

Kind ...

func (*StringSchema) Length

func (s *StringSchema) Length(length int) *StringSchema

Length ...

func (*StringSchema) LowerCase

func (s *StringSchema) LowerCase() *StringSchema

LowerCase ...

func (*StringSchema) Max

func (s *StringSchema) Max(max int) *StringSchema

Max ...

func (*StringSchema) Min

func (s *StringSchema) Min(min int) *StringSchema

Min ...

func (*StringSchema) Regex

func (s *StringSchema) Regex(regex string) *StringSchema

Regex ...

func (*StringSchema) UpperCase

func (s *StringSchema) UpperCase() *StringSchema

UpperCase ...

func (*StringSchema) Validate

func (s *StringSchema) Validate(value interface{}) error

Validate ...

type StructKeys

type StructKeys map[string]Schema

StructKeys ...

type StructSchema

type StructSchema struct {
	AnySchema
	// contains filtered or unexported fields
}

StructSchema ...

func NewStructSchema

func NewStructSchema() *StructSchema

NewStructSchema ...

func Struct

func Struct() *StructSchema

Struct ...

func (*StructSchema) Keys

func (s *StructSchema) Keys(keys StructKeys) *StructSchema

Keys ...

func (*StructSchema) Kind

func (s *StructSchema) Kind() string

Kind ...

func (*StructSchema) Validate

func (s *StructSchema) Validate(value interface{}) error

Validate ...

type TransformFunc

type TransformFunc func(interface{}) (interface{}, error)

TransformFunc function template

type TransformStage

type TransformStage int

TransformStage defines the stages

const (
	TransformStagePRE TransformStage = 1 + iota
	TransformStagePOST
)

TransformStageEnums

Jump to

Keyboard shortcuts

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