owl

package module
v1.0.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 License: MIT Imports: 9 Imported by: 0

README

a zero dependency performant validation library

Rules

Name Description Status
required not nil or zero value
default default value
enum one of a set of options

String

Name Description Status
pattern match regular expression
format match format
min min length
max max length

Numeric

Name Description Status
min minimum
max maximum

Formats

Name Status
date_time
email
ipv4
ipv6
uri
uuid

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnySchema

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

func Any

func Any() *AnySchema

func (*AnySchema) Enum

func (self *AnySchema) Enum(values ...any) *AnySchema

func (AnySchema) MarshalJSON

func (self AnySchema) MarshalJSON() ([]byte, error)

func (*AnySchema) Required

func (self *AnySchema) Required() *AnySchema

func (*AnySchema) Rule

func (self *AnySchema) Rule(key string, value any, rule RuleFn) *AnySchema

func (AnySchema) Type

func (self AnySchema) Type() string

func (AnySchema) Validate

func (self AnySchema) Validate(value any) error

type Error

type Error struct {
	Key     string  `json:"key"`
	Message string  `json:"message,omitempty"`
	Errors  []error `json:"errors,omitempty"`
}

func (Error) Add

func (self Error) Add(err error) Error

func (Error) Error

func (self Error) Error() string

func (Error) String

func (self Error) String() string

type FloatSchema

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

func Float

func Float() *FloatSchema

func (*FloatSchema) Enum

func (self *FloatSchema) Enum(values ...float64) *FloatSchema

func (FloatSchema) MarshalJSON

func (self FloatSchema) MarshalJSON() ([]byte, error)

func (*FloatSchema) Max

func (self *FloatSchema) Max(max float64) *FloatSchema

func (*FloatSchema) Min

func (self *FloatSchema) Min(min float64) *FloatSchema

func (*FloatSchema) Required

func (self *FloatSchema) Required() *FloatSchema

func (*FloatSchema) Rule

func (self *FloatSchema) Rule(key string, value any, rule RuleFn) *FloatSchema

func (FloatSchema) Type

func (FloatSchema) Type() string

func (FloatSchema) Validate

func (self FloatSchema) Validate(value any) error

type IntSchema

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

func Int

func Int() *IntSchema

func (*IntSchema) Enum

func (self *IntSchema) Enum(values ...int) *IntSchema

func (IntSchema) MarshalJSON

func (self IntSchema) MarshalJSON() ([]byte, error)

func (*IntSchema) Max

func (self *IntSchema) Max(max int) *IntSchema

func (*IntSchema) Min

func (self *IntSchema) Min(min int) *IntSchema

func (*IntSchema) Required

func (self *IntSchema) Required() *IntSchema

func (*IntSchema) Rule

func (self *IntSchema) Rule(key string, value any, rule RuleFn) *IntSchema

func (IntSchema) Type

func (self IntSchema) Type() string

func (IntSchema) Validate

func (self IntSchema) Validate(value any) error

type ObjectSchema

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

func Object

func Object() *ObjectSchema

func (*ObjectSchema) Field

func (self *ObjectSchema) Field(key string, schema Schema) *ObjectSchema

func (ObjectSchema) MarshalJSON

func (self ObjectSchema) MarshalJSON() ([]byte, error)

func (*ObjectSchema) Required

func (self *ObjectSchema) Required() *ObjectSchema

func (*ObjectSchema) Rule

func (self *ObjectSchema) Rule(key string, value any, rule RuleFn) *ObjectSchema

func (ObjectSchema) Type

func (self ObjectSchema) Type() string

func (ObjectSchema) Validate

func (self ObjectSchema) Validate(value any) error

type Rule

type Rule struct {
	Key     string `json:"key"`
	Value   any    `json:"value"`
	Resolve RuleFn `json:"-"`
}

type RuleFn

type RuleFn func(value reflect.Value) (any, error)

type Schema

type Schema interface {
	Type() string
	Validate(value any) error
	// contains filtered or unexported methods
}

type StringSchema

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

func String

func String() *StringSchema

func (*StringSchema) Email

func (self *StringSchema) Email() *StringSchema

func (*StringSchema) Enum

func (self *StringSchema) Enum(values ...string) *StringSchema

func (StringSchema) MarshalJSON

func (self StringSchema) MarshalJSON() ([]byte, error)

func (*StringSchema) Max

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

func (*StringSchema) Min

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

func (*StringSchema) Regex

func (self *StringSchema) Regex(re *regexp.Regexp) *StringSchema

func (*StringSchema) Required

func (self *StringSchema) Required() *StringSchema

func (*StringSchema) Rule

func (self *StringSchema) Rule(key string, value any, rule RuleFn) *StringSchema

func (StringSchema) Type

func (self StringSchema) Type() string

func (*StringSchema) URL

func (self *StringSchema) URL() *StringSchema

func (*StringSchema) UUID

func (self *StringSchema) UUID() *StringSchema

func (StringSchema) Validate

func (self StringSchema) Validate(value any) error

type TimeSchema

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

func Time

func Time() *TimeSchema

func (*TimeSchema) Layout

func (self *TimeSchema) Layout(layout string) *TimeSchema

func (TimeSchema) MarshalJSON

func (self TimeSchema) MarshalJSON() ([]byte, error)

func (*TimeSchema) Max

func (self *TimeSchema) Max(max time.Time) *TimeSchema

func (*TimeSchema) Min

func (self *TimeSchema) Min(min time.Time) *TimeSchema

func (*TimeSchema) Required

func (self *TimeSchema) Required() *TimeSchema

func (*TimeSchema) Rule

func (self *TimeSchema) Rule(key string, value any, rule RuleFn) *TimeSchema

func (TimeSchema) Type

func (self TimeSchema) Type() string

func (TimeSchema) Validate

func (self TimeSchema) Validate(value any) error

type UnionSchema

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

func Union

func Union(anyOf ...Schema) *UnionSchema

func (UnionSchema) MarshalJSON

func (self UnionSchema) MarshalJSON() ([]byte, error)

func (*UnionSchema) Rule

func (self *UnionSchema) Rule(key string, value any, rule RuleFn) *UnionSchema

func (UnionSchema) Type

func (self UnionSchema) Type() string

func (UnionSchema) Validate

func (self UnionSchema) Validate(value any) error

Jump to

Keyboard shortcuts

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