Documentation
¶
Index ¶
- Constants
- Variables
- func EXPERIMENTAL_RECURSIVE[T ZogSchema](build RecursiveSchemaBuilder[T]) T
- func EXPERIMENTAL_TO_ZSS(s ZSSSerializable) zss.ZSSDocument
- func RegistryAdd(_ ExMetaRegistry, _ any, _ string, _ any)
- func RegistryGet(_ ExMetaRegistry, _ any, _ string) (any, bool)
- type AnySchema
- func (v *AnySchema) Catch(val any) *AnySchema
- func (v *AnySchema) CatchFunc(catchFunc func() any) *AnySchema
- func (v *AnySchema) Default(val any) *AnySchema
- func (v *AnySchema) DefaultFunc(defaultFunc func() any) *AnySchema
- func (v *AnySchema) Optional() *AnySchema
- func (v *AnySchema) Parse(data any, dest *any, options ...ExecOption) ZogIssueList
- func (v *AnySchema) Required(options ...TestOption) *AnySchema
- func (v *AnySchema) Test(t p.Test[*any]) *AnySchema
- func (v *AnySchema) TestFunc(testFunc p.BoolTFunc[*any], options ...p.TestOption) *AnySchema
- func (v *AnySchema) Transform(transform p.Transform[*any]) *AnySchema
- func (v *AnySchema) Validate(val *any, options ...ExecOption) ZogIssueList
- type BoolSchema
- func (v *BoolSchema[T]) Catch(val T) *BoolSchema[T]
- func (v *BoolSchema[T]) CatchFunc(catchFunc func() T) *BoolSchema[T]
- func (v *BoolSchema[T]) Default(val T) *BoolSchema[T]
- func (v *BoolSchema[T]) DefaultFunc(defaultFunc func() T) *BoolSchema[T]
- func (v *BoolSchema[T]) EQ(val T) *BoolSchema[T]
- func (v *BoolSchema[T]) False() *BoolSchema[T]
- func (v *BoolSchema[T]) Optional() *BoolSchema[T]
- func (v *BoolSchema[T]) Parse(data any, dest *T, options ...ExecOption) ZogIssueList
- func (v *BoolSchema[T]) Required(options ...TestOption) *BoolSchema[T]
- func (v *BoolSchema[T]) Test(t p.Test[*T]) *BoolSchema[T]
- func (v *BoolSchema[T]) TestFunc(testFunc p.BoolTFunc[*T], options ...p.TestOption) *BoolSchema[T]
- func (v *BoolSchema[T]) Transform(transform p.Transform[*T]) *BoolSchema[T]
- func (v *BoolSchema[T]) True() *BoolSchema[T]
- func (v *BoolSchema[T]) Validate(val *T, options ...ExecOption) ZogIssueList
- type BoolTFunc
- type BoxedSchema
- type CoercerFunc
- type ComplexZogSchema
- type CreateBoxFunc
- type Ctx
- type Custom
- type CustomSchema
- type EXPERIMENTAL_PUBLIC_ZOG_SCHEMA
- type ExMetaRegistry
- type ExecOption
- type IssueFmtFunc
- type MapSchema
- func (v *MapSchema[K, V]) Default(val map[K]V) *MapSchema[K, V]
- func (v *MapSchema[K, V]) DefaultFunc(defaultFunc func() map[K]V) *MapSchema[K, V]
- func (v *MapSchema[K, V]) Len(n int, options ...TestOption) *MapSchema[K, V]
- func (v *MapSchema[K, V]) Max(n int, options ...TestOption) *MapSchema[K, V]
- func (v *MapSchema[K, V]) Min(n int, options ...TestOption) *MapSchema[K, V]
- func (v *MapSchema[K, V]) Optional() *MapSchema[K, V]
- func (v *MapSchema[K, V]) Parse(data any, dest any, options ...ExecOption) ZogIssueList
- func (v *MapSchema[K, V]) Required(options ...TestOption) *MapSchema[K, V]
- func (v *MapSchema[K, V]) Test(t Test[any]) *MapSchema[K, V]
- func (v *MapSchema[K, V]) TestFunc(testFunc BoolTFunc[any], opts ...TestOption) *MapSchema[K, V]
- func (v *MapSchema[K, V]) Transform(transform Transform[any]) *MapSchema[K, V]
- func (v *MapSchema[K, V]) Validate(data *map[K]V, options ...ExecOption) ZogIssueList
- type NotNumberSchema
- type NotSliceSchema
- type NotStringSchema
- type NumberSchema
- func Float(opts ...SchemaOption) *NumberSchema[float64]deprecated
- func Float32(opts ...SchemaOption) *NumberSchema[float32]
- func Float64(opts ...SchemaOption) *NumberSchema[float64]
- func FloatLike[T Numeric](opts ...SchemaOption) *NumberSchema[T]
- func Int(opts ...SchemaOption) *NumberSchema[int]
- func Int32(opts ...SchemaOption) *NumberSchema[int32]
- func Int64(opts ...SchemaOption) *NumberSchema[int64]
- func IntLike[T Numeric](opts ...SchemaOption) *NumberSchema[T]
- func Uint(opts ...SchemaOption) *NumberSchema[uint]
- func UintLike[T Numeric](opts ...SchemaOption) *NumberSchema[T]
- func (v *NumberSchema[T]) Catch(val T) *NumberSchema[T]
- func (v *NumberSchema[T]) CatchFunc(catchFunc func() T) *NumberSchema[T]
- func (v *NumberSchema[T]) Default(val T) *NumberSchema[T]
- func (v *NumberSchema[T]) DefaultFunc(defaultFunc func() T) *NumberSchema[T]
- func (v *NumberSchema[T]) EQ(n T, options ...TestOption) *NumberSchema[T]
- func (v *NumberSchema[T]) GT(n T, options ...TestOption) *NumberSchema[T]
- func (v *NumberSchema[T]) GTE(n T, options ...TestOption) *NumberSchema[T]
- func (v *NumberSchema[T]) LT(n T, options ...TestOption) *NumberSchema[T]
- func (v *NumberSchema[T]) LTE(n T, options ...TestOption) *NumberSchema[T]
- func (v *NumberSchema[T]) Not() NotNumberSchema[T]
- func (v *NumberSchema[T]) OneOf(enum []T, options ...TestOption) *NumberSchema[T]
- func (v *NumberSchema[T]) Optional() *NumberSchema[T]
- func (v *NumberSchema[T]) Parse(data any, dest *T, options ...ExecOption) ZogIssueList
- func (v *NumberSchema[T]) Required(options ...TestOption) *NumberSchema[T]
- func (v *NumberSchema[T]) Test(t Test[*T]) *NumberSchema[T]
- func (v *NumberSchema[T]) TestFunc(testFunc BoolTFunc[*T], options ...TestOption) *NumberSchema[T]
- func (v *NumberSchema[T]) Transform(transform p.Transform[*T]) *NumberSchema[T]
- func (v *NumberSchema[T]) Validate(data *T, options ...ExecOption) ZogIssueList
- type Numeric
- type ParsingOptiondeprecated
- type PointerSchema
- type PreprocessSchema
- type PrimitiveZogSchema
- type RecursiveSchema
- type RecursiveSchemaBuilder
- type RecursiveSchemaUpdater
- type Schemadeprecated
- type SchemaOption
- type Shape
- type SliceSchema
- func (v *SliceSchema) Contains(value any, options ...TestOption) *SliceSchema
- func (v *SliceSchema) Default(val any) *SliceSchema
- func (v *SliceSchema) DefaultFunc(defaultFunc func() any) *SliceSchema
- func (v *SliceSchema) Len(n int, options ...TestOption) *SliceSchema
- func (v *SliceSchema) Max(n int, options ...TestOption) *SliceSchema
- func (v *SliceSchema) Min(n int, options ...TestOption) *SliceSchema
- func (v *SliceSchema) Not() NotSliceSchema
- func (v *SliceSchema) Optional() *SliceSchema
- func (v *SliceSchema) Parse(data any, dest any, options ...ExecOption) ZogIssueList
- func (v *SliceSchema) Required(options ...TestOption) *SliceSchema
- func (v *SliceSchema) Test(t Test[any]) *SliceSchema
- func (v *SliceSchema) TestFunc(testFunc BoolTFunc[any], opts ...TestOption) *SliceSchema
- func (v *SliceSchema) Transform(transform Transform[any]) *SliceSchema
- func (v *SliceSchema) Validate(data any, options ...ExecOption) ZogIssueList
- type StringSchema
- func (v *StringSchema[T]) Catch(val T) *StringSchema[T]
- func (v *StringSchema[T]) CatchFunc(catchFunc func() T) *StringSchema[T]
- func (v *StringSchema[T]) Contains(sub T, options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) ContainsDigit(options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) ContainsSpecial(options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) ContainsUpper(options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) Default(val T) *StringSchema[T]
- func (v *StringSchema[T]) DefaultFunc(defaultFunc func() T) *StringSchema[T]
- func (v *StringSchema[T]) Email(options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) HasPrefix(s T, options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) HasSuffix(s T, options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) IP(options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) IPv4(options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) IPv6(options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) Len(n int, options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) Match(regex *regexp.Regexp, options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) Max(n int, options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) Min(n int, options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) Not() NotStringSchema[T]
- func (v *StringSchema[T]) OneOf(enum []T, options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) Optional() *StringSchema[T]
- func (v *StringSchema[T]) Parse(data any, dest *T, options ...ExecOption) ZogIssueList
- func (v *StringSchema[T]) Required(options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) Test(t Test[*T]) *StringSchema[T]
- func (v *StringSchema[T]) TestFunc(testFunc BoolTFunc[*T], options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) Transform(transform p.Transform[*T]) *StringSchema[T]
- func (v *StringSchema[T]) Trim() *StringSchema[T]
- func (v *StringSchema[T]) URL(options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) UUID(options ...TestOption) *StringSchema[T]
- func (v *StringSchema[T]) Validate(data *T, options ...ExecOption) ZogIssueList
- type StructSchema
- func (v *StructSchema) Extend(schema Shape) *StructSchema
- func (v *StructSchema) Merge(other *StructSchema, others ...*StructSchema) *StructSchema
- func (v *StructSchema) Omit(vals ...any) *StructSchema
- func (v *StructSchema) Optional() *StructSchemadeprecated
- func (v *StructSchema) Parse(data any, destPtr any, options ...ExecOption) ZogIssueList
- func (v *StructSchema) Pick(picks ...any) *StructSchema
- func (v *StructSchema) Required(options ...TestOption) *StructSchemadeprecated
- func (v *StructSchema) Test(t Test[any]) *StructSchema
- func (v *StructSchema) TestFunc(testFunc BoolTFunc[any], options ...TestOption) *StructSchema
- func (v *StructSchema) Transform(transform p.Transform[any]) *StructSchema
- func (v *StructSchema) Validate(dataPtr any, options ...ExecOption) ZogIssueList
- type TFunc
- type Test
- type TestOption
- type TimeFunc
- type TimeSchema
- func (v *TimeSchema) After(t time.Time, opts ...TestOption) *TimeSchema
- func (v *TimeSchema) Before(t time.Time, opts ...TestOption) *TimeSchema
- func (v *TimeSchema) Catch(val time.Time) *TimeSchema
- func (v *TimeSchema) CatchFunc(catchFunc func() time.Time) *TimeSchema
- func (v *TimeSchema) Default(val time.Time) *TimeSchema
- func (v *TimeSchema) DefaultFunc(defaultFunc func() time.Time) *TimeSchema
- func (v *TimeSchema) EQ(t time.Time, opts ...TestOption) *TimeSchema
- func (v *TimeSchema) Optional() *TimeSchema
- func (v *TimeSchema) Parse(data any, dest *time.Time, options ...ExecOption) ZogIssueList
- func (v *TimeSchema) Required(options ...TestOption) *TimeSchema
- func (v *TimeSchema) Test(t Test[*time.Time]) *TimeSchema
- func (v *TimeSchema) TestFunc(testFunc BoolTFunc[*time.Time], options ...TestOption) *TimeSchema
- func (v *TimeSchema) Transform(transform Transform[*time.Time]) *TimeSchema
- func (v *TimeSchema) Validate(data *time.Time, options ...ExecOption) ZogIssueList
- type Transform
- type UnboxFunc
- type ZSSSerializable
- type ZogIssue
- type ZogIssueList
- type ZogSchema
Constants ¶
const ( EX_META_KEY_FORMAT = "format" EX_META_KEY_MESSAGE = "message" EX_META_KEY_ID = "id" )
const (
EXHAUSTIVE_METADATA = false
)
Variables ¶
var Issues = issueHelpers{}
Functions ¶
func EXPERIMENTAL_RECURSIVE ¶ added in v0.22.1
func EXPERIMENTAL_RECURSIVE[T ZogSchema](build RecursiveSchemaBuilder[T]) T
Experimental API. Do not use unless you know what you are doing.
func EXPERIMENTAL_TO_ZSS ¶ added in v0.22.1
func EXPERIMENTAL_TO_ZSS(s ZSSSerializable) zss.ZSSDocument
func RegistryAdd ¶ added in v0.22.1
func RegistryAdd(_ ExMetaRegistry, _ any, _ string, _ any)
func RegistryGet ¶ added in v0.22.1
func RegistryGet(_ ExMetaRegistry, _ any, _ string) (any, bool)
Types ¶
type AnySchema ¶ added in v0.22.1
type AnySchema struct {
// contains filtered or unexported fields
}
func EXPERIMENTAL_ANY ¶ added in v0.22.1
func EXPERIMENTAL_ANY(opts ...SchemaOption) *AnySchema
Returns a new EXPERIMENTAL_ANY Schema Do not use unless you know what you are doing & are okay with possible breaking changes & bugs.
func (*AnySchema) Catch ¶ added in v0.22.1
sets the catch value (i.e the value to use if the validation fails)
func (*AnySchema) CatchFunc ¶ added in v0.22.1
sets the catch value (i.e the value to use if the validation fails) using a function
func (*AnySchema) DefaultFunc ¶ added in v0.22.1
sets the default value using a function
func (*AnySchema) Parse ¶ added in v0.22.1
func (v *AnySchema) Parse(data any, dest *any, options ...ExecOption) ZogIssueList
Parse data into destination pointer
func (*AnySchema) Required ¶ added in v0.22.1
func (v *AnySchema) Required(options ...TestOption) *AnySchema
marks field as required
func (*AnySchema) TestFunc ¶ added in v0.22.1
Create a custom test function for the schema. This is similar to Zod's `.refine()` method.
func (*AnySchema) Transform ¶ added in v0.22.1
Adds a transform function to the schema. Runs in the order it is called
func (*AnySchema) Validate ¶ added in v0.22.1
func (v *AnySchema) Validate(val *any, options ...ExecOption) ZogIssueList
Validate data against schema
type BoolSchema ¶ added in v0.14.1
type BoolSchema[T ~bool] struct { // contains filtered or unexported fields }
func BoolLike ¶ added in v0.21.4
func BoolLike[T ~bool](opts ...SchemaOption) *BoolSchema[T]
func (*BoolSchema[T]) Catch ¶ added in v0.14.1
func (v *BoolSchema[T]) Catch(val T) *BoolSchema[T]
sets the catch value (i.e the value to use if the validation fails)
func (*BoolSchema[T]) CatchFunc ¶ added in v0.22.1
func (v *BoolSchema[T]) CatchFunc(catchFunc func() T) *BoolSchema[T]
sets the catch value (i.e the value to use if the validation fails) using a function
func (*BoolSchema[T]) Default ¶ added in v0.14.1
func (v *BoolSchema[T]) Default(val T) *BoolSchema[T]
sets the default value
func (*BoolSchema[T]) DefaultFunc ¶ added in v0.22.1
func (v *BoolSchema[T]) DefaultFunc(defaultFunc func() T) *BoolSchema[T]
sets the default value using a function
func (*BoolSchema[T]) EQ ¶ added in v0.18.4
func (v *BoolSchema[T]) EQ(val T) *BoolSchema[T]
func (*BoolSchema[T]) False ¶ added in v0.14.1
func (v *BoolSchema[T]) False() *BoolSchema[T]
func (*BoolSchema[T]) Optional ¶ added in v0.14.1
func (v *BoolSchema[T]) Optional() *BoolSchema[T]
marks field as optional
func (*BoolSchema[T]) Parse ¶ added in v0.14.1
func (v *BoolSchema[T]) Parse(data any, dest *T, options ...ExecOption) ZogIssueList
Parse data into destination pointer
func (*BoolSchema[T]) Required ¶ added in v0.14.1
func (v *BoolSchema[T]) Required(options ...TestOption) *BoolSchema[T]
! MODIFIERS marks field as required
func (*BoolSchema[T]) Test ¶ added in v0.16.0
func (v *BoolSchema[T]) Test(t p.Test[*T]) *BoolSchema[T]
func (*BoolSchema[T]) TestFunc ¶ added in v0.16.0
func (v *BoolSchema[T]) TestFunc(testFunc p.BoolTFunc[*T], options ...p.TestOption) *BoolSchema[T]
Create a custom test function for the schema. This is similar to Zod's `.refine()` method.
func (*BoolSchema[T]) Transform ¶ added in v0.20.0
func (v *BoolSchema[T]) Transform(transform p.Transform[*T]) *BoolSchema[T]
Adds a transform function to the schema. Runs in the order it is called (i.e schema.True().Transform(...) will run the transform after the True test)
func (*BoolSchema[T]) True ¶ added in v0.14.1
func (v *BoolSchema[T]) True() *BoolSchema[T]
func (*BoolSchema[T]) Validate ¶ added in v0.15.0
func (v *BoolSchema[T]) Validate(val *T, options ...ExecOption) ZogIssueList
Validate data against schema
type BoolTFunc ¶ added in v0.19.0
Function signature for bool tests. Takes the value and the context and returns a boolean. This is the function passed to the TestFunc method.
type BoxedSchema ¶ added in v0.21.10
func Boxed ¶ added in v0.21.10
func Boxed[B any, T any](schema ZogSchema, unboxFunc UnboxFunc[B, T], boxFunc CreateBoxFunc[T, B]) *BoxedSchema[B, T]
func (*BoxedSchema[B, T]) Parse ¶ added in v0.21.10
func (s *BoxedSchema[B, T]) Parse(data any, dest any, options ...ExecOption) ZogIssueList
func (*BoxedSchema[B, T]) Validate ¶ added in v0.21.10
func (s *BoxedSchema[B, T]) Validate(dest *B, options ...ExecOption) ZogIssueList
type CoercerFunc ¶ added in v0.18.4
type CoercerFunc = conf.CoercerFunc
type ComplexZogSchema ¶ added in v0.14.1
type ComplexZogSchema interface {
ZogSchema
Parse(val any, dest any, options ...ExecOption) ZogIssueList
}
This is a common interface for all complex schemas (i.e structs, slices, pointers...) You can use this to pass any complex schema around
type CreateBoxFunc ¶ added in v0.21.10
type Ctx ¶ added in v0.15.0
This is the context that is passed through an entire execution of `schema.Parse()` or `schema.Validate()`. You can use it to pass a key/value for a specific execution. More about context in the [docs](https://zog.dev/context)
type Custom ¶ added in v0.19.1
type Custom[T any] struct { // contains filtered or unexported fields }
func CustomFunc ¶ added in v0.19.1
func CustomFunc[T any](fn func(ptr *T, ctx Ctx) bool, opts ...TestOption) *Custom[T]
func (*Custom[T]) Parse ¶ added in v0.19.1
func (c *Custom[T]) Parse(data any, destPtr *T, options ...ExecOption) ZogIssueList
func (*Custom[T]) Validate ¶ added in v0.19.1
func (c *Custom[T]) Validate(dataPtr *T, options ...ExecOption) ZogIssueList
type CustomSchema ¶ added in v0.22.0
type CustomSchema struct {
// contains filtered or unexported fields
}
Experimental API
func Use ¶ added in v0.22.0
func Use(schema EXPERIMENTAL_PUBLIC_ZOG_SCHEMA) *CustomSchema
Experimental API
type EXPERIMENTAL_PUBLIC_ZOG_SCHEMA ¶ added in v0.22.0
type EXPERIMENTAL_PUBLIC_ZOG_SCHEMA interface {
Process(ctx *p.SchemaCtx)
Validate(ctx *p.SchemaCtx)
GetType() zconst.ZogType
SetCoercer(c CoercerFunc)
ToZSS() *zss.ZSSSchema
}
Experimental API. Expect breaking changes and no documentation unfortunately for now
type ExMetaRegistry ¶ added in v0.22.1
EXPERIMENTAL. PLEASE DO NOT USE UNLESS YOU KNOW WHAT YOU ARE DOING!
type ExecOption ¶ added in v0.16.0
Options that can be passed to a `schema.Parse()` call
func WithCtxValue ¶
func WithCtxValue(key string, val any) ExecOption
func WithErrFormatter
deprecated
func WithErrFormatter(fmter IssueFmtFunc) ExecOption
Deprecated: use WithIssueFormatter instead Deprecated for naming consistency
func WithIssueFormatter ¶ added in v0.16.0
func WithIssueFormatter(fmter IssueFmtFunc) ExecOption
Sets the issue formatter for the execution context. This is used to format the issues messages during execution. This follows principle of most specific wins. So default formatter < execution formatter < test specific formatter (i.e MessageFunc)
type IssueFmtFunc ¶ added in v0.19.0
type IssueFmtFunc = p.IssueFmtFunc
Function signature for issue formatters. Takes the issue and the context and returns the formatted issue.
type MapSchema ¶ added in v0.22.1
type MapSchema[K p.ZogPrimitive, V any] struct { // contains filtered or unexported fields }
func EXPERIMENTAL_MAP ¶ added in v0.22.1
func EXPERIMENTAL_MAP[K p.ZogPrimitive, V any](keySchema PrimitiveZogSchema[K], valueSchema ZogSchema, opts ...SchemaOption) *MapSchema[K, V]
Creates a map schema. That is a Zog representation of a map. It takes a PrimitiveZogSchema for keys and a ZogSchema for values.
func (*MapSchema[K, V]) DefaultFunc ¶ added in v0.22.1
sets the default value using a function
func (*MapSchema[K, V]) Len ¶ added in v0.22.1
func (v *MapSchema[K, V]) Len(n int, options ...TestOption) *MapSchema[K, V]
Exact number of entries
func (*MapSchema[K, V]) Max ¶ added in v0.22.1
func (v *MapSchema[K, V]) Max(n int, options ...TestOption) *MapSchema[K, V]
Maximum number of entries
func (*MapSchema[K, V]) Min ¶ added in v0.22.1
func (v *MapSchema[K, V]) Min(n int, options ...TestOption) *MapSchema[K, V]
Minimum number of entries
func (*MapSchema[K, V]) Parse ¶ added in v0.22.1
func (v *MapSchema[K, V]) Parse(data any, dest any, options ...ExecOption) ZogIssueList
Parse the data into the destination map
func (*MapSchema[K, V]) Required ¶ added in v0.22.1
func (v *MapSchema[K, V]) Required(options ...TestOption) *MapSchema[K, V]
marks field as required
func (*MapSchema[K, V]) Test ¶ added in v0.22.1
custom test function call it -> schema.Test(t z.Test)
func (*MapSchema[K, V]) TestFunc ¶ added in v0.22.1
func (v *MapSchema[K, V]) TestFunc(testFunc BoolTFunc[any], opts ...TestOption) *MapSchema[K, V]
Create a custom test function for the schema. This is similar to Zod's `.refine()` method.
func (*MapSchema[K, V]) Validate ¶ added in v0.22.1
func (v *MapSchema[K, V]) Validate(data *map[K]V, options ...ExecOption) ZogIssueList
Validates a map
type NotNumberSchema ¶ added in v0.21.1
type NotNumberSchema[T Numeric] interface { OneOf(enum []T, options ...TestOption) *NumberSchema[T] EQ(n T, options ...TestOption) *NumberSchema[T] }
type NotSliceSchema ¶ added in v0.21.1
type NotSliceSchema interface {
Len(n int, options ...TestOption) *SliceSchema
Contains(value any, options ...TestOption) *SliceSchema
}
type NotStringSchema ¶ added in v0.19.2
type NotStringSchema[T likeString] interface {
OneOf(enum []T, options ...TestOption) *StringSchema[T]
Len(n int, options ...TestOption) *StringSchema[T]
Email(options ...TestOption) *StringSchema[T]
URL(options ...TestOption) *StringSchema[T]
HasPrefix(s T, options ...TestOption) *StringSchema[T]
HasSuffix(s T, options ...TestOption) *StringSchema[T]
Contains(sub T, options ...TestOption) *StringSchema[T]
ContainsUpper(options ...TestOption) *StringSchema[T]
ContainsDigit(options ...TestOption) *StringSchema[T]
ContainsSpecial(options ...TestOption) *StringSchema[T]
UUID(options ...TestOption) *StringSchema[T]
Match(regex *regexp.Regexp, options ...TestOption) *StringSchema[T]
}
type NumberSchema ¶ added in v0.14.1
type NumberSchema[T Numeric] struct { // contains filtered or unexported fields }
func Float
deprecated
func Float(opts ...SchemaOption) *NumberSchema[float64]
Deprecated: Use Float64 instead creates a new float64 schema. No plans to remove it but recommended to use Float64 instead.
func Float32 ¶ added in v0.17.0
func Float32(opts ...SchemaOption) *NumberSchema[float32]
func Float64 ¶ added in v0.17.0
func Float64(opts ...SchemaOption) *NumberSchema[float64]
func FloatLike ¶ added in v0.21.4
func FloatLike[T Numeric](opts ...SchemaOption) *NumberSchema[T]
func Int32 ¶ added in v0.17.0
func Int32(opts ...SchemaOption) *NumberSchema[int32]
func Int64 ¶ added in v0.17.0
func Int64(opts ...SchemaOption) *NumberSchema[int64]
func IntLike ¶ added in v0.21.4
func IntLike[T Numeric](opts ...SchemaOption) *NumberSchema[T]
func Uint ¶ added in v0.21.3
func Uint(opts ...SchemaOption) *NumberSchema[uint]
creates a uint schema
func UintLike ¶ added in v0.21.4
func UintLike[T Numeric](opts ...SchemaOption) *NumberSchema[T]
func (*NumberSchema[T]) Catch ¶ added in v0.14.1
func (v *NumberSchema[T]) Catch(val T) *NumberSchema[T]
sets the catch value (i.e the value to use if the validation fails)
func (*NumberSchema[T]) CatchFunc ¶ added in v0.22.1
func (v *NumberSchema[T]) CatchFunc(catchFunc func() T) *NumberSchema[T]
sets the catch value (i.e the value to use if the validation fails) using a function
func (*NumberSchema[T]) Default ¶ added in v0.14.1
func (v *NumberSchema[T]) Default(val T) *NumberSchema[T]
sets the default value
func (*NumberSchema[T]) DefaultFunc ¶ added in v0.22.1
func (v *NumberSchema[T]) DefaultFunc(defaultFunc func() T) *NumberSchema[T]
sets the default value using a function
func (*NumberSchema[T]) EQ ¶ added in v0.14.1
func (v *NumberSchema[T]) EQ(n T, options ...TestOption) *NumberSchema[T]
checks for equality
func (*NumberSchema[T]) GT ¶ added in v0.14.1
func (v *NumberSchema[T]) GT(n T, options ...TestOption) *NumberSchema[T]
checks for greater
func (*NumberSchema[T]) GTE ¶ added in v0.14.1
func (v *NumberSchema[T]) GTE(n T, options ...TestOption) *NumberSchema[T]
checks for greater or equal
func (*NumberSchema[T]) LT ¶ added in v0.14.1
func (v *NumberSchema[T]) LT(n T, options ...TestOption) *NumberSchema[T]
checks for lesser
func (*NumberSchema[T]) LTE ¶ added in v0.14.1
func (v *NumberSchema[T]) LTE(n T, options ...TestOption) *NumberSchema[T]
checks for lesser or equal
func (*NumberSchema[T]) Not ¶ added in v0.21.1
func (v *NumberSchema[T]) Not() NotNumberSchema[T]
func (*NumberSchema[T]) OneOf ¶ added in v0.14.1
func (v *NumberSchema[T]) OneOf(enum []T, options ...TestOption) *NumberSchema[T]
Check that the value is one of the enum values
func (*NumberSchema[T]) Optional ¶ added in v0.14.1
func (v *NumberSchema[T]) Optional() *NumberSchema[T]
marks field as optional
func (*NumberSchema[T]) Parse ¶ added in v0.14.1
func (v *NumberSchema[T]) Parse(data any, dest *T, options ...ExecOption) ZogIssueList
parses the value and stores it in the destination
func (*NumberSchema[T]) Required ¶ added in v0.14.1
func (v *NumberSchema[T]) Required(options ...TestOption) *NumberSchema[T]
marks field as required
func (*NumberSchema[T]) Test ¶ added in v0.14.1
func (v *NumberSchema[T]) Test(t Test[*T]) *NumberSchema[T]
custom test function call it -> schema.Test(test, options)
func (*NumberSchema[T]) TestFunc ¶ added in v0.16.0
func (v *NumberSchema[T]) TestFunc(testFunc BoolTFunc[*T], options ...TestOption) *NumberSchema[T]
Create a custom test function for the schema. This is similar to Zod's `.refine()` method.
func (*NumberSchema[T]) Transform ¶ added in v0.20.0
func (v *NumberSchema[T]) Transform(transform p.Transform[*T]) *NumberSchema[T]
Adds a transform function to the schema. Runs in the order it is called
func (*NumberSchema[T]) Validate ¶ added in v0.15.0
func (v *NumberSchema[T]) Validate(data *T, options ...ExecOption) ZogIssueList
Validates a number pointer
type ParsingOption
deprecated
type ParsingOption = ExecOption
Deprecated: use ExecOption instead
type PointerSchema ¶ added in v0.14.1
type PointerSchema struct {
// contains filtered or unexported fields
}
func Ptr ¶ added in v0.12.1
func Ptr(schema ZogSchema) *PointerSchema
Ptr creates a pointer ZogSchema
func (*PointerSchema) NotNil ¶ added in v0.14.1
func (v *PointerSchema) NotNil(options ...TestOption) *PointerSchema
func (*PointerSchema) Parse ¶ added in v0.14.1
func (v *PointerSchema) Parse(data any, dest any, options ...ExecOption) ZogIssueList
Parse the data into the destination pointer
func (*PointerSchema) Validate ¶ added in v0.15.0
func (v *PointerSchema) Validate(data any, options ...ExecOption) ZogIssueList
Validates a pointer pointer
type PreprocessSchema ¶ added in v0.20.0
func Preprocess ¶ added in v0.20.0
func Preprocess[F any, T any](fn func(data F, ctx Ctx) (out T, err error), schema ZogSchema) *PreprocessSchema[F, T]
out should never be a pointer type
func (*PreprocessSchema[F, T]) Parse ¶ added in v0.20.0
func (s *PreprocessSchema[F, T]) Parse(data F, destPtr *T, options ...ExecOption) ZogIssueList
func (*PreprocessSchema[F, T]) Validate ¶ added in v0.20.0
func (s *PreprocessSchema[F, T]) Validate(data *T, options ...ExecOption) ZogIssueList
type PrimitiveZogSchema ¶ added in v0.14.1
type PrimitiveZogSchema[T p.ZogPrimitive] interface { ZogSchema Parse(val any, dest *T, options ...ExecOption) ZogIssueList }
This is a common interface for all primitive schemas (i.e strings, numbers, booleans, time.Time...) You can use this to pass any primitive schema around
type RecursiveSchema ¶ added in v0.22.1
type RecursiveSchema[T ZogSchema] func(updaters ...RecursiveSchemaUpdater[T]) ZogSchema
type RecursiveSchemaBuilder ¶ added in v0.22.1
type RecursiveSchemaBuilder[T ZogSchema] func(self RecursiveSchema[T]) T
type RecursiveSchemaUpdater ¶ added in v0.22.1
type RecursiveSchemaUpdater[T ZogSchema] func(self T) T
type SchemaOption ¶ added in v0.12.0
type SchemaOption = func(s ZogSchema)
Options that can be passed to a `schema.New()` call
func WithCoercer ¶ added in v0.12.0
func WithCoercer(c conf.CoercerFunc) SchemaOption
type SliceSchema ¶ added in v0.14.1
type SliceSchema struct {
// contains filtered or unexported fields
}
func Slice ¶
func Slice(schema ZogSchema, opts ...SchemaOption) *SliceSchema
Creates a slice schema. That is a Zog representation of a slice. It takes a ZogSchema which will be used to validate against all the items in the slice.
func (*SliceSchema) Contains ¶ added in v0.14.1
func (v *SliceSchema) Contains(value any, options ...TestOption) *SliceSchema
Slice contains a specific value
func (*SliceSchema) Default ¶ added in v0.14.1
func (v *SliceSchema) Default(val any) *SliceSchema
sets the default value
func (*SliceSchema) DefaultFunc ¶ added in v0.22.1
func (v *SliceSchema) DefaultFunc(defaultFunc func() any) *SliceSchema
sets the default value using a function
func (*SliceSchema) Len ¶ added in v0.14.1
func (v *SliceSchema) Len(n int, options ...TestOption) *SliceSchema
Exact number of items
func (*SliceSchema) Max ¶ added in v0.14.1
func (v *SliceSchema) Max(n int, options ...TestOption) *SliceSchema
Maximum number of items
func (*SliceSchema) Min ¶ added in v0.14.1
func (v *SliceSchema) Min(n int, options ...TestOption) *SliceSchema
Minimum number of items
func (*SliceSchema) Not ¶ added in v0.21.1
func (v *SliceSchema) Not() NotSliceSchema
func (*SliceSchema) Optional ¶ added in v0.14.1
func (v *SliceSchema) Optional() *SliceSchema
marks field as optional
func (*SliceSchema) Parse ¶ added in v0.14.1
func (v *SliceSchema) Parse(data any, dest any, options ...ExecOption) ZogIssueList
Only supports parsing from data=slice[any] to a dest =&slice[] (this can be typed. Doesn't have to be any)
func (*SliceSchema) Required ¶ added in v0.14.1
func (v *SliceSchema) Required(options ...TestOption) *SliceSchema
marks field as required
func (*SliceSchema) Test ¶ added in v0.14.1
func (v *SliceSchema) Test(t Test[any]) *SliceSchema
custom test function call it -> schema.Test(t z.Test)
func (*SliceSchema) TestFunc ¶ added in v0.16.0
func (v *SliceSchema) TestFunc(testFunc BoolTFunc[any], opts ...TestOption) *SliceSchema
Create a custom test function for the schema. This is similar to Zod's `.refine()` method.
func (*SliceSchema) Transform ¶ added in v0.20.0
func (v *SliceSchema) Transform(transform Transform[any]) *SliceSchema
Adds transform function to schema.
func (*SliceSchema) Validate ¶ added in v0.15.0
func (v *SliceSchema) Validate(data any, options ...ExecOption) ZogIssueList
Validates a slice
type StringSchema ¶ added in v0.14.1
type StringSchema[T likeString] struct {
// contains filtered or unexported fields
}
func StringLike ¶ added in v0.21.4
func StringLike[T likeString](opts ...SchemaOption) *StringSchema[T]
func (*StringSchema[T]) Catch ¶ added in v0.14.1
func (v *StringSchema[T]) Catch(val T) *StringSchema[T]
sets the catch value (i.e the value to use if the validation fails)
func (*StringSchema[T]) CatchFunc ¶ added in v0.22.1
func (v *StringSchema[T]) CatchFunc(catchFunc func() T) *StringSchema[T]
sets the catch value (i.e the value to use if the validation fails) using a function
func (*StringSchema[T]) Contains ¶ added in v0.14.1
func (v *StringSchema[T]) Contains(sub T, options ...TestOption) *StringSchema[T]
Test: checks that the value contains the substring
func (*StringSchema[T]) ContainsDigit ¶ added in v0.14.1
func (v *StringSchema[T]) ContainsDigit(options ...TestOption) *StringSchema[T]
Test: checks that the value contains a digit
func (*StringSchema[T]) ContainsSpecial ¶ added in v0.14.1
func (v *StringSchema[T]) ContainsSpecial(options ...TestOption) *StringSchema[T]
Test: checks that the value contains a special character
func (*StringSchema[T]) ContainsUpper ¶ added in v0.14.1
func (v *StringSchema[T]) ContainsUpper(options ...TestOption) *StringSchema[T]
Test: checks that the value contains an uppercase letter
func (*StringSchema[T]) Default ¶ added in v0.14.1
func (v *StringSchema[T]) Default(val T) *StringSchema[T]
sets the default value
func (*StringSchema[T]) DefaultFunc ¶ added in v0.22.1
func (v *StringSchema[T]) DefaultFunc(defaultFunc func() T) *StringSchema[T]
sets the default value using a function
func (*StringSchema[T]) Email ¶ added in v0.14.1
func (v *StringSchema[T]) Email(options ...TestOption) *StringSchema[T]
Test: checks that the value is a valid email address
func (*StringSchema[T]) HasPrefix ¶ added in v0.14.1
func (v *StringSchema[T]) HasPrefix(s T, options ...TestOption) *StringSchema[T]
Test: checks that the value has the prefix
func (*StringSchema[T]) HasSuffix ¶ added in v0.14.1
func (v *StringSchema[T]) HasSuffix(s T, options ...TestOption) *StringSchema[T]
Test: checks that the value has the suffix
func (*StringSchema[T]) IP ¶ added in v0.21.9
func (v *StringSchema[T]) IP(options ...TestOption) *StringSchema[T]
Test: checks that the value is a valid IP address (IPv4 or IPv6)
func (*StringSchema[T]) IPv4 ¶ added in v0.21.8
func (v *StringSchema[T]) IPv4(options ...TestOption) *StringSchema[T]
Test: checks that the value is a valid IPv4 address
func (*StringSchema[T]) IPv6 ¶ added in v0.21.9
func (v *StringSchema[T]) IPv6(options ...TestOption) *StringSchema[T]
Test: checks that the value is a valid IPv6 address
func (*StringSchema[T]) Len ¶ added in v0.14.1
func (v *StringSchema[T]) Len(n int, options ...TestOption) *StringSchema[T]
Test: checks that the value is exactly n characters long
func (*StringSchema[T]) Match ¶ added in v0.14.1
func (v *StringSchema[T]) Match(regex *regexp.Regexp, options ...TestOption) *StringSchema[T]
Test: checks that value matches to regex
func (*StringSchema[T]) Max ¶ added in v0.14.1
func (v *StringSchema[T]) Max(n int, options ...TestOption) *StringSchema[T]
Test: checks that the value is at most n characters long
func (*StringSchema[T]) Min ¶ added in v0.14.1
func (v *StringSchema[T]) Min(n int, options ...TestOption) *StringSchema[T]
Test: checks that the value is at least n characters long
func (*StringSchema[T]) Not ¶ added in v0.19.2
func (v *StringSchema[T]) Not() NotStringSchema[T]
Not returns a schema that negates the next validation test. For example, `z.String().Not().Email()` validates that the string is NOT a valid email. Note: The negation only applies to the next validation test and is reset afterward.
func (*StringSchema[T]) OneOf ¶ added in v0.14.1
func (v *StringSchema[T]) OneOf(enum []T, options ...TestOption) *StringSchema[T]
Test: checks that the value is one of the enum values
func (*StringSchema[T]) Optional ¶ added in v0.14.1
func (v *StringSchema[T]) Optional() *StringSchema[T]
marks field as optional
func (*StringSchema[T]) Parse ¶ added in v0.14.1
func (v *StringSchema[T]) Parse(data any, dest *T, options ...ExecOption) ZogIssueList
Parses the data into the destination string. Returns a list of ZogIssues
func (*StringSchema[T]) Required ¶ added in v0.14.1
func (v *StringSchema[T]) Required(options ...TestOption) *StringSchema[T]
marks field as required
func (*StringSchema[T]) Test ¶ added in v0.14.1
func (v *StringSchema[T]) Test(t Test[*T]) *StringSchema[T]
! Tests custom test function call it -> schema.Test(t z.Test, opts ...TestOption)
func (*StringSchema[T]) TestFunc ¶ added in v0.16.0
func (v *StringSchema[T]) TestFunc(testFunc BoolTFunc[*T], options ...TestOption) *StringSchema[T]
Create a custom test function for the schema. This is similar to Zod's `.refine()` method.
func (*StringSchema[T]) Transform ¶ added in v0.20.0
func (v *StringSchema[T]) Transform(transform p.Transform[*T]) *StringSchema[T]
Adds a transform function to the schema. Runs in the order it is called
func (*StringSchema[T]) Trim ¶ added in v0.14.1
func (v *StringSchema[T]) Trim() *StringSchema[T]
Transform: trims the input data of whitespace if it is a string
func (*StringSchema[T]) URL ¶ added in v0.14.1
func (v *StringSchema[T]) URL(options ...TestOption) *StringSchema[T]
Test: checks that the value is a valid URL
func (*StringSchema[T]) UUID ¶ added in v0.14.1
func (v *StringSchema[T]) UUID(options ...TestOption) *StringSchema[T]
Test: checks that the value is a valid uuid
func (*StringSchema[T]) Validate ¶ added in v0.15.0
func (v *StringSchema[T]) Validate(data *T, options ...ExecOption) ZogIssueList
Validate Given string
type StructSchema ¶ added in v0.14.1
type StructSchema struct {
// contains filtered or unexported fields
}
func Struct ¶
func Struct(schema Shape) *StructSchema
Returns a new StructSchema which can be used to parse input data into a struct
func (*StructSchema) Extend ¶ added in v0.14.1
func (v *StructSchema) Extend(schema Shape) *StructSchema
Extend creates a new schema by adding additional fields from the provided schema. Fields in the provided schema override any existing fields with the same key.
Parameters:
- schema: The schema containing fields to add
Returns a new schema with the additional fields
func (*StructSchema) Merge ¶ added in v0.14.1
func (v *StructSchema) Merge(other *StructSchema, others ...*StructSchema) *StructSchema
Merge combines two or more schemas into a new schema. It performs a shallow merge, meaning:
- Fields with the same key from later schemas override earlier ones
- Modifying nested schemas may affect the original schemas
Parameters:
- other: The first schema to merge with
- others: Additional schemas to merge
Returns a new schema containing the merged fields and transforms
func (*StructSchema) Omit ¶ added in v0.14.1
func (v *StructSchema) Omit(vals ...any) *StructSchema
Omit creates a new schema with specified fields removed. It accepts either strings or map[string]bool as arguments:
- Strings directly specify fields to omit
- For maps, fields are omitted when their boolean value is true
Returns a new schema with the specified fields removed
func (*StructSchema) Optional
deprecated
added in
v0.14.1
func (v *StructSchema) Optional() *StructSchema
Deprecated: structs are not required or optional. They pass through to the fields. If you want to say that an entire struct may not exist you should use z.Ptr(z.Struct(...)) marks field as optional
func (*StructSchema) Parse ¶ added in v0.14.1
func (v *StructSchema) Parse(data any, destPtr any, options ...ExecOption) ZogIssueList
Parses val into destPtr and validates each field based on the schema. Only supports val = map[string]any & dest = &struct
func (*StructSchema) Pick ¶ added in v0.14.1
func (v *StructSchema) Pick(picks ...any) *StructSchema
Pick creates a new schema keeping only the specified fields. It accepts either strings or map[string]bool as arguments:
- Strings directly specify fields to keep
- For maps, fields are kept when their boolean value is true
Returns a new schema containing only the specified fields
func (*StructSchema) Required
deprecated
added in
v0.14.1
func (v *StructSchema) Required(options ...TestOption) *StructSchema
Deprecated: structs are not required or optional. They pass through to the fields. If you want to say that an entire struct may not exist you should use z.Ptr(z.Struct(...)) This now is a noop. But I believe most people expect it to work how it does now. marks field as required
func (*StructSchema) Test ¶ added in v0.14.1
func (v *StructSchema) Test(t Test[any]) *StructSchema
! VALIDATORS custom test function call it -> schema.Test(t z.Test)
func (*StructSchema) TestFunc ¶ added in v0.16.0
func (v *StructSchema) TestFunc(testFunc BoolTFunc[any], options ...TestOption) *StructSchema
Create a custom test function for the schema. This is similar to Zod's `.refine()` method.
func (*StructSchema) Transform ¶ added in v0.20.0
func (v *StructSchema) Transform(transform p.Transform[any]) *StructSchema
Adds posttransform function to schema
func (*StructSchema) Validate ¶ added in v0.15.0
func (v *StructSchema) Validate(dataPtr any, options ...ExecOption) ZogIssueList
Validate a struct pointer given the struct schema. Usage: userSchema.Validate(&User, ...options)
type TFunc ¶ added in v0.19.0
Function signature for tests. Takes the value and the context and returns a boolean. This used to be a function you could pass to the schema.Test method -> `s.Test(z.TFunc(fn))`. But that has been deprecated. Use `schema.TFunc(fn)` instead.
type Test ¶
Test is the test object. It is the struct that represents an individual validation. For example `z.String().Min(3)` is a test that checks if the string is at least 3 characters long.
func TestFunc ¶
func TestFunc[T any](IssueCode zconst.ZogIssueCode, fn BoolTFunc[T], options ...p.TestOption) Test[T]
Creates a reusable testFunc you can add to schemas by doing schema.Test(z.TestFunc()). Has the same API as schema.TestFunc() so it is recommended you use that one for non reusable tests.
type TestOption ¶
type TestOption = p.TestOption
Options that can be passed to a test
func IssueCode ¶ added in v0.16.0
func IssueCode(code zconst.ZogIssueCode) TestOption
IssueCode is a function that allows you to set a custom issue code for the test. Most useful for TestFuncs:
z.String().TestFunc(..., z.IssueCode("just_provide_a_string" or use values in zconst))
func IssuePath ¶ added in v0.16.0
func IssuePath(path []string) TestOption
IssuePath is a function that allows you to set a custom issue path for the test. Beware with using this as it is not typesafe and can lead to unexpected behavior if you change the schema or have a typo. Usage:
z.Struct(
z.Shape {
"Name": z.String().Required(z.IssuePath("fullname")),
"Fullname": z.String(),
}
)
func Message ¶
func Message(msg string) TestOption
Message is a function that allows you to set a custom message for the test.
func MessageFunc ¶
func MessageFunc(fn p.IssueFmtFunc) TestOption
MessageFunc is a function that allows you to set a custom message formatter for the test.
func Params ¶ added in v0.16.1
func Params(params map[string]any) TestOption
Params is a function that allows you to set a custom params for the test. You may then access these values when formatting test errors in the IssueFmtFunc
type TimeFunc ¶ added in v0.12.0
type TimeFunc func(opts ...SchemaOption) *TimeSchema
var Time TimeFunc = func(opts ...SchemaOption) *TimeSchema { t := &TimeSchema{ coercer: conf.Coercers.Time, } for _, opt := range opts { opt(t) } return t }
Returns a new Time Shape
func (TimeFunc) Format ¶ added in v0.12.0
func (t TimeFunc) Format(format string) SchemaOption
WARNING ONLY SUPPOORTS Shape.Parse! Sets the string format for the time schema Usage is: z.Time(z.Time.Format(time.RFC3339))
func (TimeFunc) FormatFunc ¶ added in v0.12.0
WARNING ONLY SUPPOORTS Shape.Parse! Sets the format function for the time schema. Usage is:
z.Time(z.Time.FormatFunc(func(data string) (time.Time, error) {
return time.Parse(time.RFC3339, data)
}))
type TimeSchema ¶ added in v0.14.1
type TimeSchema struct {
// contains filtered or unexported fields
}
func (*TimeSchema) After ¶ added in v0.14.1
func (v *TimeSchema) After(t time.Time, opts ...TestOption) *TimeSchema
Checks that the value is after the given time
func (*TimeSchema) Before ¶ added in v0.14.1
func (v *TimeSchema) Before(t time.Time, opts ...TestOption) *TimeSchema
Checks that the value is before the given time
func (*TimeSchema) Catch ¶ added in v0.14.1
func (v *TimeSchema) Catch(val time.Time) *TimeSchema
sets the catch value (i.e the value to use if the validation fails)
func (*TimeSchema) CatchFunc ¶ added in v0.22.1
func (v *TimeSchema) CatchFunc(catchFunc func() time.Time) *TimeSchema
sets the catch value (i.e the value to use if the validation fails) using a function
func (*TimeSchema) Default ¶ added in v0.14.1
func (v *TimeSchema) Default(val time.Time) *TimeSchema
sets the default value
func (*TimeSchema) DefaultFunc ¶ added in v0.22.1
func (v *TimeSchema) DefaultFunc(defaultFunc func() time.Time) *TimeSchema
sets the default value using a function
func (*TimeSchema) EQ ¶ added in v0.14.1
func (v *TimeSchema) EQ(t time.Time, opts ...TestOption) *TimeSchema
Checks that the value is equal to the given time
func (*TimeSchema) Optional ¶ added in v0.14.1
func (v *TimeSchema) Optional() *TimeSchema
marks field as optional
func (*TimeSchema) Parse ¶ added in v0.14.1
func (v *TimeSchema) Parse(data any, dest *time.Time, options ...ExecOption) ZogIssueList
Parses the data into the destination time.Time. Returns a list of errors
func (*TimeSchema) Required ¶ added in v0.14.1
func (v *TimeSchema) Required(options ...TestOption) *TimeSchema
marks field as required
func (*TimeSchema) Test ¶ added in v0.14.1
func (v *TimeSchema) Test(t Test[*time.Time]) *TimeSchema
custom test function call it -> schema.Test(z.Test{Func: func (val *time.Time, ctx z.Ctx) { my test }})
func (*TimeSchema) TestFunc ¶ added in v0.16.0
func (v *TimeSchema) TestFunc(testFunc BoolTFunc[*time.Time], options ...TestOption) *TimeSchema
Create a custom test function for the schema. This is similar to Zod's `.refine()` method.
func (*TimeSchema) Transform ¶ added in v0.20.0
func (v *TimeSchema) Transform(transform Transform[*time.Time]) *TimeSchema
Adds posttransform function to schema
func (*TimeSchema) Validate ¶ added in v0.15.0
func (v *TimeSchema) Validate(data *time.Time, options ...ExecOption) ZogIssueList
Validates an existing time.Time
type Transform ¶ added in v0.20.0
Function signature for transforms. Takes the value pointer and the context and returns an optional error.
type ZSSSerializable ¶ added in v0.22.1
type ZSSSerializable interface {
// contains filtered or unexported methods
}
type ZogIssue ¶ added in v0.16.0
This is a type for the ZogIssue type. It is the type of all the errors returned from zog.
type ZogIssueList ¶ added in v0.16.0
type ZogIssueList = p.ZogIssueList
ZogIssueList is the type returned by all schema Parse/Validate operations. It is a slice of pointers to ZogIssue.
type ZogSchema ¶ added in v0.12.0
type ZogSchema interface {
// contains filtered or unexported methods
}
The ZogSchema is the interface all schemas must implement This is most useful for internal use. If you are looking to pass schemas around, use the ComplexZogSchema or PrimitiveZogSchema interfaces if possible.