Documentation
¶
Overview ¶
Package checks provides validation check factories for the GoZod validation library. It implements Zod v4-compatible check creation with JSON Schema metadata support.
Package checks provides validation check factories and utilities for creating reusable validation rules that can be attached to schemas.
Index ¶
- func ApplyCheckParams(def *core.ZodCheckDef, cp *core.CheckParams)
- func ApplySchemaParamsToCheck(def *core.ZodCheckDef, sp *core.SchemaParams)
- func Base64(params ...any) core.ZodCheck
- func Base64URL(params ...any) core.ZodCheck
- func BrowserEmail(params ...any) core.ZodCheck
- func CIDRv4(params ...any) core.ZodCheck
- func CIDRv6(params ...any) core.ZodCheck
- func CUID(params ...any) core.ZodCheck
- func CUID2(params ...any) core.ZodCheck
- func Describe(description string) core.ZodCheck
- func E164(params ...any) core.ZodCheck
- func Email(params ...any) core.ZodCheck
- func EmailWithPattern(pattern *regexp.Regexp, params ...any) core.ZodCheck
- func Emoji(params ...any) core.ZodCheck
- func Empty(params ...any) core.ZodCheck
- func EndsWith(suffix string, params ...any) core.ZodCheck
- func FileSize(expected int64, params ...any) core.ZodCheck
- func GUID(params ...any) core.ZodCheck
- func Gt(value any, params ...any) core.ZodCheck
- func Gte(value any, params ...any) core.ZodCheck
- func HTML5Email(params ...any) core.ZodCheck
- func Hex(params ...any) core.ZodCheck
- func Hostname(params ...any) core.ZodCheck
- func IPv4(params ...any) core.ZodCheck
- func IPv6(params ...any) core.ZodCheck
- func ISODate(params ...any) core.ZodCheck
- func ISODateMax(maxDate string, params ...any) core.ZodCheck
- func ISODateMin(minDate string, params ...any) core.ZodCheck
- func ISODateTime(params ...any) core.ZodCheck
- func ISODateTimeWithOptions(options validate.ISODateTimeOptions, params ...any) core.ZodCheck
- func ISODuration(params ...any) core.ZodCheck
- func ISOTime(params ...any) core.ZodCheck
- func ISOTimeWithOptions(options validate.ISOTimeOptions, params ...any) core.ZodCheck
- func Includes(substring string, params ...any) core.ZodCheck
- func JSON(params ...any) core.ZodCheck
- func JWT(params ...any) core.ZodCheck
- func JWTWithAlgorithm(algorithm string, params ...any) core.ZodCheck
- func JWTWithOptions(options validate.JWTOptions, params ...any) core.ZodCheck
- func KSUID(params ...any) core.ZodCheck
- func Length(exact int, params ...any) core.ZodCheck
- func LengthRange(minimum, maximum int, params ...any) core.ZodCheck
- func Lowercase(params ...any) core.ZodCheck
- func Lt(value any, params ...any) core.ZodCheck
- func Lte(value any, params ...any) core.ZodCheck
- func MAC(params ...any) core.ZodCheck
- func MACWithDelimiter(delimiter string, params ...any) core.ZodCheck
- func MACWithOptions(options validate.MACOptions, params ...any) core.ZodCheck
- func MD5(params ...any) core.ZodCheck
- func MaxFileSize(maximum int64, params ...any) core.ZodCheck
- func MaxLength(maximum int, params ...any) core.ZodCheck
- func MaxSize(maximum int, params ...any) core.ZodCheck
- func Meta(metadata core.GlobalMeta) core.ZodCheck
- func Mime(mimeTypes []string, params ...any) core.ZodCheck
- func MinFileSize(minimum int64, params ...any) core.ZodCheck
- func MinLength(minimum int, params ...any) core.ZodCheck
- func MinSize(minimum int, params ...any) core.ZodCheck
- func MultipleOf(divisor any, params ...any) core.ZodCheck
- func NanoID(params ...any) core.ZodCheck
- func Negative(params ...any) core.ZodCheck
- func NonEmpty(params ...any) core.ZodCheck
- func NonNegative(params ...any) core.ZodCheck
- func NonPositive(params ...any) core.ZodCheck
- func NormalizeCheckParams(params ...any) *core.CheckParams
- func Positive(params ...any) core.ZodCheck
- func PrefixIssues(path any, iss []core.ZodRawIssue) []core.ZodRawIssue
- func RFC5322Email(params ...any) core.ZodCheck
- func Regex(pattern *regexp.Regexp, params ...any) core.ZodCheck
- func SHA1(params ...any) core.ZodCheck
- func SHA256(params ...any) core.ZodCheck
- func SHA384(params ...any) core.ZodCheck
- func SHA512(params ...any) core.ZodCheck
- func SetBagProperty(schema any, key string, value any)
- func Size(exact int, params ...any) core.ZodCheck
- func SizeRange(minimum, maximum int, params ...any) core.ZodCheck
- func StartsWith(prefix string, params ...any) core.ZodCheck
- func StringGte(minValue string, params ...any) core.ZodCheck
- func StringLte(maxValue string, params ...any) core.ZodCheck
- func ULID(params ...any) core.ZodCheck
- func URL(params ...any) core.ZodCheck
- func URLWithOptions(options validate.URLOptions, params ...any) core.ZodCheck
- func UUID(params ...any) core.ZodCheck
- func UUID6(params ...any) core.ZodCheck
- func UUID7(params ...any) core.ZodCheck
- func UUIDv4(params ...any) core.ZodCheck
- func UnicodeEmail(params ...any) core.ZodCheck
- func Uppercase(params ...any) core.ZodCheck
- func XID(params ...any) core.ZodCheck
- type ZodCheckCustom
- type ZodCheckCustomDef
- type ZodCheckCustomInternals
- type ZodCheckDescribe
- type ZodCheckMeta
- type ZodCheckOverwrite
- type ZodCheckOverwriteDef
- type ZodCheckOverwriteInternals
- type ZodCheckProperty
- type ZodCheckPropertyDef
- type ZodCheckPropertyInternals
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyCheckParams ¶ added in v0.3.0
func ApplyCheckParams(def *core.ZodCheckDef, cp *core.CheckParams)
ApplyCheckParams applies normalized parameters to a check definition.
func ApplySchemaParamsToCheck ¶ added in v0.3.0
func ApplySchemaParamsToCheck(def *core.ZodCheckDef, sp *core.SchemaParams)
ApplySchemaParamsToCheck applies SchemaParams to a check definition.
func BrowserEmail ¶ added in v0.3.0
BrowserEmail creates a browser-compatible email validation check.
func Describe ¶ added in v0.5.4
Describe creates a no-op check that registers a description in the global registry when attached to a schema.
Example:
schema := gozod.String().Check(gozod.Describe("User email"))
func EmailWithPattern ¶ added in v0.3.0
EmailWithPattern creates an email validation check with a custom regex pattern.
func HTML5Email ¶ added in v0.6.0
HTML5Email creates an HTML5 email validation check.
func ISODateMax ¶ added in v0.3.0
ISODateMax creates a maximum date validation check. Validates that the ISO date is on or before the specified maximum date.
func ISODateMin ¶ added in v0.3.0
ISODateMin creates a minimum date validation check. Validates that the ISO date is on or after the specified minimum date.
func ISODateTime ¶
ISODateTime creates an ISO 8601 datetime format validation check.
func ISODateTimeWithOptions ¶ added in v0.3.0
func ISODateTimeWithOptions(options validate.ISODateTimeOptions, params ...any) core.ZodCheck
ISODateTimeWithOptions creates an ISO 8601 datetime validation check with options.
func ISODuration ¶
ISODuration creates an ISO 8601 duration validation check.
func ISOTimeWithOptions ¶ added in v0.3.0
func ISOTimeWithOptions(options validate.ISOTimeOptions, params ...any) core.ZodCheck
ISOTimeWithOptions creates an ISO 8601 time validation check with configuration. Uses self-reference to attach Inst on the created issue.
func JWTWithAlgorithm ¶ added in v0.3.0
JWTWithAlgorithm creates a JWT token validation check with algorithm constraint.
func JWTWithOptions ¶ added in v0.5.3
func JWTWithOptions(options validate.JWTOptions, params ...any) core.ZodCheck
JWTWithOptions creates a JWT token validation check with full configuration.
func LengthRange ¶
LengthRange creates a length range validation check.
func MACWithDelimiter ¶ added in v0.5.3
MACWithDelimiter creates a MAC address validation check with a custom delimiter.
func MACWithOptions ¶ added in v0.5.3
func MACWithOptions(options validate.MACOptions, params ...any) core.ZodCheck
MACWithOptions creates a MAC address validation check with full configuration.
func MaxFileSize ¶ added in v0.3.0
MaxFileSize creates a maximum file size validation check.
func Meta ¶ added in v0.5.4
func Meta(metadata core.GlobalMeta) core.ZodCheck
Meta creates a no-op check that merges metadata into the global registry when attached to a schema.
Example:
schema := gozod.Number().Check(gozod.Meta(gozod.GlobalMeta{
Title: "Age",
Description: "User's age",
}))
func MinFileSize ¶ added in v0.3.0
MinFileSize creates a minimum file size validation check.
func MultipleOf ¶
MultipleOf creates a multiple-of validation check.
func NonNegative ¶
NonNegative creates a check that the value is greater than or equal to zero.
func NonPositive ¶
NonPositive creates a check that the value is less than or equal to zero.
func NormalizeCheckParams ¶ added in v0.3.0
func NormalizeCheckParams(params ...any) *core.CheckParams
NormalizeCheckParams standardizes check parameters from various input formats. It accepts a string shorthand or core.SchemaParams.
func PrefixIssues ¶
func PrefixIssues(path any, iss []core.ZodRawIssue) []core.ZodRawIssue
PrefixIssues prepends a path segment to all issues for nested validation.
func RFC5322Email ¶ added in v0.6.0
RFC5322Email creates an RFC 5322 email validation check.
func SetBagProperty ¶ added in v0.3.0
SetBagProperty sets a property in the schema's bag for JSON Schema generation.
func StartsWith ¶
StartsWith creates a prefix validation check.
func StringGte ¶ added in v0.3.0
StringGte creates a string greater-than-or-equal check using lexicographic comparison, suitable for ISO 8601 date/time strings.
func StringLte ¶ added in v0.3.0
StringLte creates a string less-than-or-equal check using lexicographic comparison, suitable for ISO 8601 date/time strings.
func URLWithOptions ¶ added in v0.3.0
func URLWithOptions(options validate.URLOptions, params ...any) core.ZodCheck
URLWithOptions creates a URL validation check with optional constraints.
func UnicodeEmail ¶ added in v0.3.0
UnicodeEmail creates a Unicode email validation check.
Types ¶
type ZodCheckCustom ¶
type ZodCheckCustom struct {
Internals *ZodCheckCustomInternals
}
ZodCheckCustom represents a custom validation check.
func NewCustom ¶
func NewCustom[T any](fn any, args ...any) *ZodCheckCustom
NewCustom creates a custom validation check with user-defined logic.
func (*ZodCheckCustom) Zod ¶ added in v0.6.0
func (c *ZodCheckCustom) Zod() *core.ZodCheckInternals
Zod returns the internal check structure for execution.
type ZodCheckCustomDef ¶
type ZodCheckCustomDef struct {
core.ZodCheckDef
Type string // check type identifier
Params map[string]any // additional parameters
Fn any // RefineFn or CheckFn
FnType string // "refine" or "check"
}
ZodCheckCustomDef defines a custom validation constraint.
type ZodCheckCustomInternals ¶
type ZodCheckCustomInternals struct {
core.ZodCheckInternals
Def *ZodCheckCustomDef
Issc *core.ZodIssueBase
Bag map[string]any
}
ZodCheckCustomInternals contains custom check internal state.
type ZodCheckDescribe ¶ added in v0.5.4
type ZodCheckDescribe struct {
// contains filtered or unexported fields
}
ZodCheckDescribe is a no-op check that attaches a description to the schema's metadata in the global registry.
func (*ZodCheckDescribe) Zod ¶ added in v0.6.0
func (c *ZodCheckDescribe) Zod() *core.ZodCheckInternals
Zod returns the internal check structure for execution.
type ZodCheckMeta ¶ added in v0.5.4
type ZodCheckMeta struct {
// contains filtered or unexported fields
}
ZodCheckMeta is a no-op check that attaches arbitrary metadata to the schema's metadata in the global registry.
func (*ZodCheckMeta) Zod ¶ added in v0.6.0
func (c *ZodCheckMeta) Zod() *core.ZodCheckInternals
Zod returns the internal check structure for execution.
type ZodCheckOverwrite ¶
type ZodCheckOverwrite struct {
Internals *ZodCheckOverwriteInternals
}
ZodCheckOverwrite represents a check that replaces the payload value.
func NewZodCheckOverwrite ¶
func NewZodCheckOverwrite(transform func(any) any, args ...any) *ZodCheckOverwrite
NewZodCheckOverwrite creates a check that overwrites input with a transformed value.
func (*ZodCheckOverwrite) Zod ¶ added in v0.6.0
func (c *ZodCheckOverwrite) Zod() *core.ZodCheckInternals
Zod returns the internal check structure for execution.
type ZodCheckOverwriteDef ¶
type ZodCheckOverwriteDef struct {
core.ZodCheckDef
Transform func(any) any
}
ZodCheckOverwriteDef defines a value transformation constraint.
type ZodCheckOverwriteInternals ¶
type ZodCheckOverwriteInternals struct {
core.ZodCheckInternals
Def *ZodCheckOverwriteDef
}
ZodCheckOverwriteInternals contains overwrite check internal state.
type ZodCheckProperty ¶ added in v0.3.0
type ZodCheckProperty struct {
Internals *ZodCheckPropertyInternals
}
ZodCheckProperty validates a specific object property against a schema.
func NewProperty ¶ added in v0.3.0
func NewProperty(property string, schema core.ZodSchema, args ...any) *ZodCheckProperty
NewProperty creates a property validation check that validates input[property] against the provided schema.
func (*ZodCheckProperty) Zod ¶ added in v0.6.0
func (c *ZodCheckProperty) Zod() *core.ZodCheckInternals
Zod returns the internal check structure for execution.
type ZodCheckPropertyDef ¶ added in v0.3.0
type ZodCheckPropertyDef struct {
core.ZodCheckDef
Property string
Schema core.ZodSchema
}
ZodCheckPropertyDef defines a property validation constraint.
type ZodCheckPropertyInternals ¶ added in v0.3.0
type ZodCheckPropertyInternals struct {
core.ZodCheckInternals
Def *ZodCheckPropertyDef
Issc *core.ZodIssueBase
}
ZodCheckPropertyInternals contains property check internal state.