Documentation ¶
Index ¶
- type AnySchema
- func (self *AnySchema) Enum(values ...any) *AnySchema
- func (self AnySchema) MarshalJSON() ([]byte, error)
- func (self *AnySchema) Message(message string) *AnySchema
- func (self *AnySchema) Required() *AnySchema
- func (self *AnySchema) Rule(key string, value any, rule RuleFn) *AnySchema
- func (self AnySchema) Type() string
- func (self AnySchema) Validate(value any) error
- type ArraySchema
- func (self ArraySchema) MarshalJSON() ([]byte, error)
- func (self *ArraySchema) Max(max int) *ArraySchema
- func (self *ArraySchema) Message(message string) *ArraySchema
- func (self *ArraySchema) Min(min int) *ArraySchema
- func (self *ArraySchema) Required() *ArraySchema
- func (self *ArraySchema) Rule(key string, value any, rule RuleFn) *ArraySchema
- func (self ArraySchema) Type() string
- func (self ArraySchema) Validate(value any) error
- type BoolSchema
- func (self *BoolSchema) Enum(values ...bool) *BoolSchema
- func (self BoolSchema) MarshalJSON() ([]byte, error)
- func (self *BoolSchema) Message(message string) *BoolSchema
- func (self *BoolSchema) Required() *BoolSchema
- func (self *BoolSchema) Rule(key string, value any, rule RuleFn) *BoolSchema
- func (self BoolSchema) Type() string
- func (self BoolSchema) Validate(value any) error
- type Error
- type ErrorGroup
- type FloatSchema
- func (self *FloatSchema) Enum(values ...float64) *FloatSchema
- func (self FloatSchema) MarshalJSON() ([]byte, error)
- func (self *FloatSchema) Max(max float64) *FloatSchema
- func (self *FloatSchema) Message(message string) *FloatSchema
- func (self *FloatSchema) Min(min float64) *FloatSchema
- func (self *FloatSchema) Required() *FloatSchema
- func (self *FloatSchema) Rule(key string, value any, rule RuleFn) *FloatSchema
- func (FloatSchema) Type() string
- func (self FloatSchema) Validate(value any) error
- type IntSchema
- func (self *IntSchema) Enum(values ...int) *IntSchema
- func (self IntSchema) MarshalJSON() ([]byte, error)
- func (self *IntSchema) Max(max int) *IntSchema
- func (self *IntSchema) Message(message string) *IntSchema
- func (self *IntSchema) Min(min int) *IntSchema
- func (self *IntSchema) Required() *IntSchema
- func (self *IntSchema) Rule(key string, value any, rule RuleFn) *IntSchema
- func (self IntSchema) Type() string
- func (self IntSchema) Validate(value any) error
- type ObjectSchema
- func (self *ObjectSchema) Extend(schema *ObjectSchema) *ObjectSchema
- func (self *ObjectSchema) Field(key string, schema Schema) *ObjectSchema
- func (self *ObjectSchema) Fields(fields map[string]Schema) *ObjectSchema
- func (self ObjectSchema) MarshalJSON() ([]byte, error)
- func (self *ObjectSchema) Message(message string) *ObjectSchema
- func (self *ObjectSchema) Required() *ObjectSchema
- func (self *ObjectSchema) Rule(key string, value any, rule RuleFn) *ObjectSchema
- func (self ObjectSchema) Type() string
- func (self ObjectSchema) Validate(value any) error
- type Rule
- type RuleFn
- type Schema
- type StringSchema
- func (self *StringSchema) Email() *StringSchema
- func (self *StringSchema) Enum(values ...string) *StringSchema
- func (self StringSchema) MarshalJSON() ([]byte, error)
- func (self *StringSchema) Max(max int) *StringSchema
- func (self *StringSchema) Message(message string) *StringSchema
- func (self *StringSchema) Min(min int) *StringSchema
- func (self *StringSchema) Regex(re *regexp.Regexp) *StringSchema
- func (self *StringSchema) Required() *StringSchema
- func (self *StringSchema) Rule(key string, value any, rule RuleFn) *StringSchema
- func (self StringSchema) Type() string
- func (self *StringSchema) URL() *StringSchema
- func (self *StringSchema) UUID() *StringSchema
- func (self StringSchema) Validate(value any) error
- type TimeSchema
- func (self *TimeSchema) Layout(layout string) *TimeSchema
- func (self TimeSchema) MarshalJSON() ([]byte, error)
- func (self *TimeSchema) Max(max time.Time) *TimeSchema
- func (self *TimeSchema) Message(message string) *TimeSchema
- func (self *TimeSchema) Min(min time.Time) *TimeSchema
- func (self *TimeSchema) Required() *TimeSchema
- func (self *TimeSchema) Rule(key string, value any, rule RuleFn) *TimeSchema
- func (self TimeSchema) Type() string
- func (self TimeSchema) Validate(value any) error
- type UnionSchema
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnySchema ¶
type AnySchema []Rule
func Any ¶
func Any() *AnySchema
Example ¶
package main import ( "github.com/aacebo/owl" ) func main() { schema := owl.Any() if err := schema.Validate("..."); err != nil { // nil panic(err) } if err := schema.Validate(1); err != nil { // nil panic(err) } if err := schema.Validate(true); err != nil { // nil panic(err) } }
Output:
func (AnySchema) MarshalJSON ¶
func (*AnySchema) Rule ¶
Example ¶
package main import ( "errors" "net" "reflect" "github.com/aacebo/owl" ) func main() { schema := owl.Any().Rule("ipv4", nil, func(value reflect.Value) (any, error) { if !value.IsValid() { return nil, nil } if ip := net.ParseIP(value.String()); ip == nil { return nil, errors.New("must be a valid ipv4 address") } return value.String(), nil }) if err := schema.Validate("192.168.0.1"); err != nil { // nil panic(err) } if err := schema.Validate("192.168.0"); err != nil { // error panic(err) } }
Output:
type ArraySchema ¶
type ArraySchema struct {
// contains filtered or unexported fields
}
func Array ¶
func Array(schema Schema) *ArraySchema
Example ¶
package main import ( "github.com/aacebo/owl" ) func main() { schema := owl.Array(owl.String().Required()) if err := schema.Validate([]string{"test"}); err != nil { // nil panic(err) } if err := schema.Validate([]int{1}); err != nil { // error panic(err) } }
Output:
func (ArraySchema) MarshalJSON ¶
func (self ArraySchema) MarshalJSON() ([]byte, error)
func (*ArraySchema) Max ¶
func (self *ArraySchema) Max(max int) *ArraySchema
func (*ArraySchema) Message ¶
func (self *ArraySchema) Message(message string) *ArraySchema
func (*ArraySchema) Min ¶
func (self *ArraySchema) Min(min int) *ArraySchema
func (*ArraySchema) Required ¶
func (self *ArraySchema) Required() *ArraySchema
func (*ArraySchema) Rule ¶
func (self *ArraySchema) Rule(key string, value any, rule RuleFn) *ArraySchema
func (ArraySchema) Type ¶
func (self ArraySchema) Type() string
func (ArraySchema) Validate ¶
func (self ArraySchema) Validate(value any) error
type BoolSchema ¶
type BoolSchema struct {
// contains filtered or unexported fields
}
func Bool ¶
func Bool() *BoolSchema
Example ¶
package main import ( "github.com/aacebo/owl" ) func main() { schema := owl.Bool() if err := schema.Validate(true); err != nil { // nil panic(err) } if err := schema.Validate(false); err != nil { // nil panic(err) } if err := schema.Validate("test"); err != nil { // error panic(err) } }
Output:
func (*BoolSchema) Enum ¶
func (self *BoolSchema) Enum(values ...bool) *BoolSchema
func (BoolSchema) MarshalJSON ¶
func (self BoolSchema) MarshalJSON() ([]byte, error)
func (*BoolSchema) Message ¶
func (self *BoolSchema) Message(message string) *BoolSchema
func (*BoolSchema) Required ¶
func (self *BoolSchema) Required() *BoolSchema
func (*BoolSchema) Rule ¶
func (self *BoolSchema) Rule(key string, value any, rule RuleFn) *BoolSchema
func (BoolSchema) Type ¶
func (self BoolSchema) Type() string
func (BoolSchema) Validate ¶
func (self BoolSchema) Validate(value any) error
type Error ¶
type Error struct { Rule string `json:"rule,omitempty"` Key string `json:"key,omitempty"` Message string `json:"message,omitempty"` Errors []error `json:"errors,omitempty"` }
func NewEmptyError ¶
type ErrorGroup ¶
type ErrorGroup []error
func (ErrorGroup) Error ¶
func (self ErrorGroup) Error() string
func (ErrorGroup) String ¶
func (self ErrorGroup) String() string
type FloatSchema ¶
type FloatSchema struct {
// contains filtered or unexported fields
}
func Float ¶
func Float() *FloatSchema
Example ¶
package main import ( "github.com/aacebo/owl" ) func main() { schema := owl.Float() if err := schema.Validate(1.0); err != nil { // nil panic(err) } if err := schema.Validate(1); err != nil { // nil panic(err) } if err := schema.Validate("test"); err != nil { // error panic(err) } }
Output:
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
Example ¶
package main import ( "github.com/aacebo/owl" ) func main() { schema := owl.Float().Max(5.0) if err := schema.Validate(5); err != nil { // nil panic(err) } if err := schema.Validate(5.5); err != nil { // error panic(err) } }
Output:
func (*FloatSchema) Message ¶
func (self *FloatSchema) Message(message string) *FloatSchema
func (*FloatSchema) Min ¶
func (self *FloatSchema) Min(min float64) *FloatSchema
Example ¶
package main import ( "github.com/aacebo/owl" ) func main() { schema := owl.Float().Min(5.0) if err := schema.Validate(5); err != nil { // nil panic(err) } if err := schema.Validate(4.5); err != nil { // error panic(err) } }
Output:
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
Example ¶
package main import ( "github.com/aacebo/owl" ) func main() { schema := owl.Int() if err := schema.Validate(1); err != nil { // nil panic(err) } if err := schema.Validate(1); err != nil { // nil panic(err) } if err := schema.Validate("test"); err != nil { // error panic(err) } }
Output:
func (IntSchema) MarshalJSON ¶
func (*IntSchema) Max ¶
Example ¶
package main import ( "github.com/aacebo/owl" ) func main() { schema := owl.Int().Max(5) if err := schema.Validate(5); err != nil { // nil panic(err) } if err := schema.Validate(6); err != nil { // error panic(err) } }
Output:
type ObjectSchema ¶
type ObjectSchema struct {
// contains filtered or unexported fields
}
func Object ¶
func Object() *ObjectSchema
Example ¶
package main import ( "github.com/aacebo/owl" ) func main() { schema := owl.Object().Field( "email", owl.String().Email().Required(), ).Field( "password", owl.String().Min(5).Max(20).Required(), ) if err := schema.Validate(map[string]any{ "email": "test@test.com", "password": "mytestpassword", }); err != nil { // nil panic(err) } if err := schema.Validate(map[string]any{ "email": "test@test.com", }); err != nil { // error panic(err) } }
Output:
func (*ObjectSchema) Extend ¶
func (self *ObjectSchema) Extend(schema *ObjectSchema) *ObjectSchema
func (*ObjectSchema) Field ¶
func (self *ObjectSchema) Field(key string, schema Schema) *ObjectSchema
func (*ObjectSchema) Fields ¶
func (self *ObjectSchema) Fields(fields map[string]Schema) *ObjectSchema
func (ObjectSchema) MarshalJSON ¶
func (self ObjectSchema) MarshalJSON() ([]byte, error)
func (*ObjectSchema) Message ¶
func (self *ObjectSchema) Message(message string) *ObjectSchema
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 StringSchema ¶
type StringSchema struct {
// contains filtered or unexported fields
}
func String ¶
func String() *StringSchema
Example ¶
package main import ( "github.com/aacebo/owl" ) func main() { schema := owl.String() if err := schema.Validate("test"); err != nil { // nil panic(err) } if err := schema.Validate(true); err != nil { // error panic(err) } }
Output:
func (*StringSchema) Email ¶
func (self *StringSchema) Email() *StringSchema
Example ¶
package main import ( "github.com/aacebo/owl" ) func main() { schema := owl.String().Email() if err := schema.Validate("test@gmail.com"); err != nil { // nil panic(err) } if err := schema.Validate("test"); err != nil { // error panic(err) } }
Output:
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
Example ¶
package main import ( "github.com/aacebo/owl" ) func main() { schema := owl.String().Max(5) if err := schema.Validate("test"); err != nil { // nil panic(err) } if err := schema.Validate("tester"); err != nil { // error panic(err) } }
Output:
func (*StringSchema) Message ¶
func (self *StringSchema) Message(message string) *StringSchema
func (*StringSchema) Min ¶
func (self *StringSchema) Min(min int) *StringSchema
Example ¶
package main import ( "github.com/aacebo/owl" ) func main() { schema := owl.String().Min(5) if err := schema.Validate("tester"); err != nil { // nil panic(err) } if err := schema.Validate("test"); err != nil { // error panic(err) } }
Output:
func (*StringSchema) Regex ¶
func (self *StringSchema) Regex(re *regexp.Regexp) *StringSchema
Example ¶
package main import ( "regexp" "github.com/aacebo/owl" ) func main() { schema := owl.String().Regex(regexp.MustCompile("^[0-9a-zA-Z_-]+$")) if err := schema.Validate("test"); err != nil { // nil panic(err) } if err := schema.Validate("hello world"); err != nil { // error panic(err) } }
Output:
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
Example ¶
package main import ( "github.com/aacebo/owl" ) func main() { schema := owl.String().URL() if err := schema.Validate("https://www.google.com"); err != nil { // nil panic(err) } if err := schema.Validate("test"); err != nil { // error panic(err) } }
Output:
func (*StringSchema) UUID ¶
func (self *StringSchema) UUID() *StringSchema
Example ¶
package main import ( "github.com/aacebo/owl" ) func main() { schema := owl.String().UUID() if err := schema.Validate("afefc1ab-b8f2-4803-8e9a-60515854141a"); err != nil { // nil panic(err) } if err := schema.Validate("test"); err != nil { // error panic(err) } }
Output:
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
Example ¶
package main import ( "time" "github.com/aacebo/owl" ) func main() { schema := owl.Time() if err := schema.Validate(time.Now()); err != nil { // nil panic(err) } if err := schema.Validate(time.Now().Format(time.RFC3339)); err != nil { // nil panic(err) } if err := schema.Validate("test"); err != nil { // error panic(err) } }
Output:
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
Example ¶
package main import ( "time" "github.com/aacebo/owl" ) func main() { schema := owl.Time().Max(time.Now()) if err := schema.Validate(time.Now().AddDate(1, 0, 0)); err != nil { // error panic(err) } }
Output:
func (*TimeSchema) Message ¶
func (self *TimeSchema) Message(message string) *TimeSchema
func (*TimeSchema) Min ¶
func (self *TimeSchema) Min(min time.Time) *TimeSchema
Example ¶
package main import ( "time" "github.com/aacebo/owl" ) func main() { schema := owl.Time().Min(time.Now()) if err := schema.Validate(time.Now().AddDate(-1, 0, 0)); err != nil { // error panic(err) } }
Output:
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
Example ¶
package main import ( "github.com/aacebo/owl" ) func main() { schema := owl.Union( owl.String().Required(), owl.Int().Required(), ) if err := schema.Validate("test"); err != nil { // nil panic(err) } if err := schema.Validate(1); err != nil { // nil panic(err) } if err := schema.Validate(true); err != nil { // error panic(err) } }
Output:
func (UnionSchema) MarshalJSON ¶
func (self UnionSchema) MarshalJSON() ([]byte, error)
func (*UnionSchema) Message ¶
func (self *UnionSchema) Message(message string) *UnionSchema
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
Source Files ¶
Click to show internal directories.
Click to hide internal directories.