gozod

package module
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 6 Imported by: 1

README

GoZod

Go Version License

A TypeScript Zod v4-inspired validation library for Go with strict type semantics, fluent schemas, and JSON Schema interoperability

Features

  • Strict type semantics: Value and pointer schemas accept exact input types unless you explicitly opt into coercion.
  • Dual parsing modes: Use Parse(any) for dynamic data and StrictParse(T) when the input type is already known.
  • Rich schema surface: Compose primitives, collections, structs, unions, intersections, metadata, transforms, and refinements.
  • Struct tags: Build schemas from Go structs with gozod:"..." rules and alternate tag names through WithTagName.
  • Optional code generation: Use gozodgen for generated schema helpers in tag-heavy hot paths.
  • Localized errors: Inspect *gozod.ZodError, flatten or prettify failures, and use locale bundles from locales/.
  • JSON Schema bridge: Convert to and from JSON Schema Draft 2020-12 with the bundled jsonschema package.
  • Curated dependency surface: Built on JSON v2, jsonschema, deepclone, and i18n helpers instead of a framework stack.

Installation

go get github.com/kaptinlin/gozod

Requires Go 1.26+.

Quick Start

package main

import (
	"fmt"
	"log"

	"github.com/kaptinlin/gozod"
)

func main() {
	schema := gozod.String().Min(2).Email()

	value, err := schema.Parse("dev@example.com")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(value)
}

Parse and StrictParse

GoZod keeps runtime parsing and compile-time constrained parsing separate.

nameSchema := gozod.String().Min(2).Max(50)

name, err := nameSchema.Parse("Alice")
if err != nil {
	log.Fatal(err)
}

strictName, err := nameSchema.StrictParse("Alice")
if err != nil {
	log.Fatal(err)
}

fmt.Println(name, strictName)

Use Parse(any) when data arrives from JSON, maps, or other dynamic sources. Use StrictParse(T) when your program already has the target Go type and you want the strict side of the API.

Struct Tags and Generated Schemas

Use FromStruct[T]() for declarative validation on native Go structs.

package main

import (
	"fmt"
	"log"

	"github.com/kaptinlin/gozod"
)

type User struct {
	Name  string `gozod:"required,min=2,max=50"`
	Email string `gozod:"required,email"`
	Age   int    `gozod:"min=18,max=120"`
}

func main() {
	schema := gozod.FromStruct[User]()

	user, err := schema.Parse(User{
		Name:  "Ada Lovelace",
		Email: "ada@example.com",
		Age:   36,
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%+v\n", user)
}

If you use a different tag key, pass gozod.WithTagName("validate").

For generated helpers, install and run gozodgen:

go install github.com/kaptinlin/gozod/cmd/gozodgen@latest
go generate ./...

See docs/tags.md and cmd/gozodgen for the full struct-tag and code-generation workflow.

Programmatic Schemas

Use Object, Struct, Union, Intersection, and related constructors when you want the schema shape in code.

userSchema := gozod.Object(gozod.ObjectSchema{
	"name":  gozod.String().Min(2),
	"email": gozod.Email(),
	"age":   gozod.Int().Min(18),
})

contactSchema := gozod.Union([]any{
	gozod.Email(),
	gozod.URL(),
})

_, _ = userSchema.Parse(map[string]any{
	"name":  "Grace",
	"email": "grace@example.com",
	"age":   28,
})

_, _ = contactSchema.Parse("https://example.com")

For coercion-first flows, use the constructors in coerce/.

JSON Schema Integration

GoZod can translate schemas to JSON Schema Draft 2020-12 and back.

schema := gozod.Object(gozod.ObjectSchema{
	"name": gozod.String().Min(1),
	"age":  gozod.Int().Min(0),
})

jsonSchema, err := gozod.ToJSONSchema(schema)
if err != nil {
	log.Fatal(err)
}

result := jsonSchema.ValidateMap(map[string]any{
	"name": "Lin",
	"age":  30,
})

fmt.Println(result.IsValid())

See docs/json-schema.md for conversion details and compatibility notes.

Error Handling

Validation failures return error. Inspect them as *gozod.ZodError when you need structured details.

schema := gozod.String().Min(5)
_, err := schema.Parse("hi")
if err == nil {
	return
}

var zodErr *gozod.ZodError
if gozod.IsZodError(err, &zodErr) {
	fmt.Println(gozod.PrettifyError(zodErr))
}

See docs/error-customization.md and docs/error-formatting.md for custom messages and output shapes.

Examples and Documentation

Run an example directly:

go run ./examples/quickstart
go run ./examples/struct_tags

Performance

GoZod includes benchmarks for parsing, checks, tags, transforms, and configuration helpers.

  • Prefer StrictParse when the input type is already known.
  • Use coerce/ only when conversion is part of the requirement.
  • Use gozodgen for tag-heavy hot paths where reflection cost matters.

Run the benchmark suite with:

go test -bench=. ./...

Development

task test                         # Run the default test suite
task test:race                    # Run race-enabled tests for lightweight packages
task lint                         # Run golangci-lint and tidy checks
task verify                       # Run deps, fmt, vet, lint, test, and govulncheck
go test -tags=contractcheck ./types # Audit compile-time schema contracts

For development guidelines and repository conventions, see AGENTS.md.

Contributing

Contributions are welcome. Run the test and lint commands before opening a pull request, and keep docs and examples aligned with the current API surface.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Overview

Package gozod provides a TypeScript Zod v4-inspired validation library for Go, offering strongly-typed data validation with intelligent type inference.

Index

Constants

View Source
const (
	IssueInvalidType      = core.InvalidType
	IssueInvalidValue     = core.InvalidValue
	IssueInvalidFormat    = core.InvalidFormat
	IssueInvalidUnion     = core.InvalidUnion
	IssueInvalidKey       = core.InvalidKey
	IssueInvalidElement   = core.InvalidElement
	IssueTooBig           = core.TooBig
	IssueTooSmall         = core.TooSmall
	IssueNotMultipleOf    = core.NotMultipleOf
	IssueUnrecognizedKeys = core.UnrecognizedKeys
	IssueCustom           = core.Custom
)

Issue code constants.

Variables

View Source
var (
	Array                 = types.Array
	ArrayPtr              = types.ArrayPtr
	Map                   = types.Map
	MapPtr                = types.MapPtr
	Tuple                 = types.Tuple
	TupleWithRest         = types.TupleWithRest
	TuplePtr              = types.TuplePtr
	LooseRecord           = types.LooseRecord
	LooseRecordPtr        = types.LooseRecordPtr
	Object                = types.Object
	ObjectPtr             = types.ObjectPtr
	StrictObject          = types.StrictObject
	StrictObjectPtr       = types.StrictObjectPtr
	LooseObject           = types.LooseObject
	LooseObjectPtr        = types.LooseObjectPtr
	Union                 = types.Union
	UnionPtr              = types.UnionPtr
	Xor                   = types.Xor
	XorPtr                = types.XorPtr
	XorOf                 = types.XorOf
	Intersection          = types.Intersection
	IntersectionPtr       = types.IntersectionPtr
	DiscriminatedUnion    = types.DiscriminatedUnion
	DiscriminatedUnionPtr = types.DiscriminatedUnionPtr
)
View Source
var (
	String               = types.String
	StringPtr            = types.StringPtr
	Email                = types.Email
	EmailPtr             = types.EmailPtr
	Emoji                = types.Emoji
	EmojiPtr             = types.EmojiPtr
	Base64               = types.Base64
	Base64Ptr            = types.Base64Ptr
	Base64URL            = types.Base64URL
	Base64URLPtr         = types.Base64URLPtr
	Hex                  = types.Hex
	HexPtr               = types.HexPtr
	Bool                 = types.Bool
	BoolPtr              = types.BoolPtr
	Int                  = types.Int
	IntPtr               = types.IntPtr
	Int8                 = types.Int8
	Int8Ptr              = types.Int8Ptr
	Int16                = types.Int16
	Int16Ptr             = types.Int16Ptr
	Int32                = types.Int32
	Int32Ptr             = types.Int32Ptr
	Int64                = types.Int64
	Int64Ptr             = types.Int64Ptr
	Uint                 = types.Uint
	UintPtr              = types.UintPtr
	Uint8                = types.Uint8
	Uint8Ptr             = types.Uint8Ptr
	Uint16               = types.Uint16
	Uint16Ptr            = types.Uint16Ptr
	Uint32               = types.Uint32
	Uint32Ptr            = types.Uint32Ptr
	Uint64               = types.Uint64
	Uint64Ptr            = types.Uint64Ptr
	Float                = types.Float
	FloatPtr             = types.FloatPtr
	Float32              = types.Float32
	Float32Ptr           = types.Float32Ptr
	Float64              = types.Float64
	Float64Ptr           = types.Float64Ptr
	Number               = types.Number
	NumberPtr            = types.NumberPtr
	BigInt               = types.BigInt
	BigIntPtr            = types.BigIntPtr
	Complex              = types.Complex
	ComplexPtr           = types.ComplexPtr
	Complex64            = types.Complex64
	Complex64Ptr         = types.Complex64Ptr
	Complex128           = types.Complex128
	Complex128Ptr        = types.Complex128Ptr
	Time                 = types.Time
	TimePtr              = types.TimePtr
	IPv4                 = types.IPv4
	IPv4Ptr              = types.IPv4Ptr
	IPv6                 = types.IPv6
	IPv6Ptr              = types.IPv6Ptr
	CIDRv4               = types.CIDRv4
	CIDRv4Ptr            = types.CIDRv4Ptr
	CIDRv6               = types.CIDRv6
	CIDRv6Ptr            = types.CIDRv6Ptr
	URL                  = types.URL
	URLPtr               = types.URLPtr
	Hostname             = types.Hostname
	HostnamePtr          = types.HostnamePtr
	MAC                  = types.MAC
	MACPtr               = types.MACPtr
	MACWithDelimiter     = types.MACWithDelimiter
	E164                 = types.E164
	E164Ptr              = types.E164Ptr
	HTTPURL              = types.HTTPURL
	HTTPURLPtr           = types.HTTPURLPtr
	Iso                  = types.Iso
	IsoPtr               = types.IsoPtr
	IsoDateTime          = types.IsoDateTime
	IsoDateTimePtr       = types.IsoDateTimePtr
	IsoDate              = types.IsoDate
	IsoDatePtr           = types.IsoDatePtr
	IsoTime              = types.IsoTime
	IsoTimePtr           = types.IsoTimePtr
	IsoDuration          = types.IsoDuration
	IsoDurationPtr       = types.IsoDurationPtr
	PrecisionMinute      = types.PrecisionMinute
	PrecisionSecond      = types.PrecisionSecond
	PrecisionDecisecond  = types.PrecisionDecisecond
	PrecisionCentisecond = types.PrecisionCentisecond
	PrecisionMillisecond = types.PrecisionMillisecond
	PrecisionMicrosecond = types.PrecisionMicrosecond
	PrecisionNanosecond  = types.PrecisionNanosecond
	CUID                 = types.CUID
	CUIDPtr              = types.CUIDPtr
	CUID2                = types.CUID2
	CUID2Ptr             = types.CUID2Ptr
	GUID                 = types.GUID
	GUIDPtr              = types.GUIDPtr
	ULID                 = types.ULID
	ULIDPtr              = types.ULIDPtr
	XID                  = types.XID
	XIDPtr               = types.XIDPtr
	KSUID                = types.KSUID
	KSUIDPtr             = types.KSUIDPtr
	NanoID               = types.NanoID
	NanoIDPtr            = types.NanoIDPtr
	UUID                 = types.UUID
	UUIDPtr              = types.UUIDPtr
	UUIDv4               = types.UUIDv4
	UUIDv4Ptr            = types.UUIDv4Ptr
	UUIDv6               = types.UUIDv6
	UUIDv6Ptr            = types.UUIDv6Ptr
	UUIDv7               = types.UUIDv7
	UUIDv7Ptr            = types.UUIDv7Ptr
	JWT                  = types.JWT
	JWTPtr               = types.JWTPtr
)
View Source
var (
	Any           = types.Any
	AnyPtr        = types.AnyPtr
	Unknown       = types.Unknown
	UnknownPtr    = types.UnknownPtr
	Never         = types.Never
	NeverPtr      = types.NeverPtr
	Nil           = types.Nil
	NilPtr        = types.NilPtr
	File          = types.File
	FilePtr       = types.FilePtr
	Function      = types.Function
	FunctionPtr   = types.FunctionPtr
	StringBool    = types.StringBool
	StringBoolPtr = types.StringBoolPtr
	LazyAny       = types.LazyAny
	LazyPtr       = types.LazyPtr
)
View Source
var (
	SetConfig = core.SetConfig
	Config    = core.Config
)

Global configuration functions.

View Source
var (
	TreeifyError               = issues.TreeifyError
	PrettifyError              = issues.PrettifyError
	FlattenError               = issues.FlattenError
	FormatError                = issues.FormatError
	TreeifyErrorWithMapper     = issues.TreeifyErrorWithMapper
	PrettifyErrorWithFormatter = issues.PrettifyErrorWithFormatter
	FlattenErrorWithMapper     = issues.FlattenErrorWithMapper
	FlattenErrorWithFormatter  = issues.FlattenErrorWithFormatter
	ToDotPath                  = utils.ToDotPath
	FormatErrorPath            = utils.FormatErrorPath
)
View Source
var (
	ToJSONSchema                     = jsonschema.ToJSONSchema
	FromJSONSchema                   = jsonschema.FromJSONSchema
	ErrUnsupportedInputType          = jsonschema.ErrUnsupportedInputType
	ErrCircularReference             = jsonschema.ErrCircularReference
	ErrUnrepresentableType           = jsonschema.ErrUnrepresentableType
	ErrSchemaNotObjectOrStruct       = jsonschema.ErrSchemaNotObjectOrStruct
	ErrSliceElementNotSchema         = jsonschema.ErrSliceElementNotSchema
	ErrArrayItemNotSchema            = jsonschema.ErrArrayItemNotSchema
	ErrUnhandledArrayLike            = jsonschema.ErrUnhandledArrayLike
	ErrUnionInvalid                  = jsonschema.ErrUnionInvalid
	ErrUnionNoMembers                = jsonschema.ErrUnionNoMembers
	ErrIntersectionInvalid           = jsonschema.ErrIntersectionInvalid
	ErrInvalidEnumSchema             = jsonschema.ErrInvalidEnumSchema
	ErrEnumExtractValues             = jsonschema.ErrEnumExtractValues
	ErrLiteralNoValuesMethod         = jsonschema.ErrLiteralNoValuesMethod
	ErrLiteralUnexpectedReturnValues = jsonschema.ErrLiteralUnexpectedReturnValues
	ErrExpectedDiscriminatedUnion    = jsonschema.ErrExpectedDiscriminatedUnion
	ErrExpectedRecord                = jsonschema.ErrExpectedRecord
	ErrRecordValueNotSchema          = jsonschema.ErrRecordValueNotSchema
	ErrMapNoMethods                  = jsonschema.ErrMapNoMethods
	ErrMapKeyNotSchema               = jsonschema.ErrMapKeyNotSchema
	ErrMapValueNotSchema             = jsonschema.ErrMapValueNotSchema
	ErrUnsupportedJSONSchemaType     = jsonschema.ErrUnsupportedJSONSchemaType
	ErrUnsupportedJSONSchemaKeyword  = jsonschema.ErrUnsupportedJSONSchemaKeyword
	ErrInvalidJSONSchema             = jsonschema.ErrInvalidJSONSchema
	ErrJSONSchemaCircularRef         = jsonschema.ErrJSONSchemaCircularRef
	ErrJSONSchemaPatternCompile      = jsonschema.ErrJSONSchemaPatternCompile
	ErrJSONSchemaIfThenElse          = jsonschema.ErrJSONSchemaIfThenElse
	ErrJSONSchemaPatternProperties   = jsonschema.ErrJSONSchemaPatternProperties
	ErrJSONSchemaDynamicRef          = jsonschema.ErrJSONSchemaDynamicRef
	ErrJSONSchemaUnevaluatedProps    = jsonschema.ErrJSONSchemaUnevaluatedProps
	ErrJSONSchemaUnevaluatedItems    = jsonschema.ErrJSONSchemaUnevaluatedItems
	ErrJSONSchemaDependentSchemas    = jsonschema.ErrJSONSchemaDependentSchemas
	ErrJSONSchemaPropertyNames       = jsonschema.ErrJSONSchemaPropertyNames
	ErrJSONSchemaContains            = jsonschema.ErrJSONSchemaContains
)
View Source
var (
	GlobalRegistry = core.GlobalRegistry
	Describe       = checks.Describe
	Meta           = checks.Meta
)
View Source
var IsZodError = issues.IsZodError

Functions

func Apply added in v0.5.4

func Apply[S any, R any](schema S, fn func(S) R) R

Apply integrates external functions into schema chains.

func FromStruct added in v0.5.0

func FromStruct[T any](opts ...FromStructOption) *types.ZodStruct[T, T]

func FromStructPtr added in v0.5.0

func FromStructPtr[T any](opts ...FromStructOption) *types.ZodStruct[T, *T]

func Lazy

func Lazy[S types.ZodSchemaType](getter func() S, params ...any) *types.ZodLazyTyped[S]

Types

type CheckParams added in v0.3.0

type CheckParams = core.CheckParams

Validation check aliases.

type CustomParams added in v0.3.1

type CustomParams = core.CustomParams

Validation check aliases.

type FlattenedError

type FlattenedError = issues.FlattenedError

type FromJSONSchemaOptions added in v0.5.4

type FromJSONSchemaOptions = jsonschema.FromJSONSchemaOptions

type FromStructOption added in v0.8.0

type FromStructOption = types.FromStructOption

func WithTagName added in v0.8.0

func WithTagName(name string) FromStructOption

type GlobalMeta added in v0.3.1

type GlobalMeta = core.GlobalMeta

type IsoDatetimeOptions added in v0.3.0

type IsoDatetimeOptions = types.IsoDatetimeOptions

Public schema type aliases.

type IsoTimeOptions added in v0.3.0

type IsoTimeOptions = types.IsoTimeOptions

Public schema type aliases.

type IssueCode

type IssueCode = core.IssueCode

Validation payload and issue code aliases.

type JSONSchemaOptions added in v0.3.1

type JSONSchemaOptions = jsonschema.Options

type JWTOptions added in v0.3.0

type JWTOptions = types.JWTOptions

Public schema type aliases.

type MessageFormatter added in v0.3.0

type MessageFormatter = issues.MessageFormatter

type ObjectSchema

type ObjectSchema = core.ObjectSchema

Schema and configuration aliases.

type OverrideContext added in v0.3.1

type OverrideContext = jsonschema.OverrideContext

type ParsePayload

type ParsePayload = core.ParsePayload

Validation payload and issue code aliases.

type Registry added in v0.3.1

type Registry[M any] = core.Registry[M]

func NewRegistry added in v0.3.1

func NewRegistry[M any]() *Registry[M]

type SchemaParams

type SchemaParams = core.SchemaParams

Schema and configuration aliases.

type StructSchema added in v0.2.0

type StructSchema = core.StructSchema

Schema and configuration aliases.

type URLOptions added in v0.3.0

type URLOptions = types.URLOptions

Public schema type aliases.

type Unwrapper added in v0.8.0

type Unwrapper = core.Unwrapper

Unwrapper allows wrapper types to expose their underlying value for validation.

type ZodAny

type ZodAny[T any, R any] = types.ZodAny[T, R]

Public schema type aliases.

type ZodArray

type ZodArray[T any, R any] = types.ZodArray[T, R]

Public schema type aliases.

type ZodBase64 added in v0.3.0

type ZodBase64[T types.StringConstraint] = types.ZodBase64[T]

Public schema type aliases.

type ZodBase64URL added in v0.3.0

type ZodBase64URL[T types.StringConstraint] = types.ZodBase64URL[T]

Public schema type aliases.

type ZodBool

type ZodBool[T types.BoolConstraint] = types.ZodBool[T]

Public schema type aliases.

type ZodCIDRv4

type ZodCIDRv4[T types.StringConstraint] = types.ZodCIDRv4[T]

Public schema type aliases.

type ZodCIDRv6

type ZodCIDRv6[T types.StringConstraint] = types.ZodCIDRv6[T]

Public schema type aliases.

type ZodCUID added in v0.3.0

type ZodCUID[T types.StringConstraint] = types.ZodCUID[T]

Public schema type aliases.

type ZodCUID2 added in v0.3.0

type ZodCUID2[T types.StringConstraint] = types.ZodCUID2[T]

Public schema type aliases.

type ZodCheck

type ZodCheck = core.ZodCheck

Validation check aliases.

type ZodCheckDef

type ZodCheckDef = core.ZodCheckDef

Validation check aliases.

type ZodCheckFn

type ZodCheckFn = core.ZodCheckFn

Validation check aliases.

type ZodCheckInternals

type ZodCheckInternals = core.ZodCheckInternals

Validation check aliases.

type ZodComplex

type ZodComplex[T types.ComplexConstraint] = types.ZodComplex[T]

Public schema type aliases.

type ZodConfig

type ZodConfig = core.ZodConfig

Schema and configuration aliases.

type ZodDiscriminatedUnion

type ZodDiscriminatedUnion[T any, R any] = types.ZodDiscriminatedUnion[T, R]

Public schema type aliases.

type ZodE164 added in v0.5.4

type ZodE164[T types.StringConstraint] = types.ZodE164[T]

Public schema type aliases.

type ZodEmail added in v0.3.0

type ZodEmail[T types.EmailConstraint] = types.ZodEmail[T]

Public schema type aliases.

type ZodEmoji added in v0.3.0

type ZodEmoji[T types.StringConstraint] = types.ZodEmoji[T]

Public schema type aliases.

type ZodEnum

type ZodEnum[T comparable, R any] = types.ZodEnum[T, R]

Public schema type aliases.

func Enum

func Enum[T comparable](values ...T) *ZodEnum[T, T]

func EnumMap

func EnumMap[T comparable](entries map[string]T, params ...any) *ZodEnum[T, T]

func EnumMapPtr added in v0.3.0

func EnumMapPtr[T comparable](entries map[string]T, params ...any) *ZodEnum[T, *T]

func EnumPtr added in v0.3.0

func EnumPtr[T comparable](values ...T) *ZodEnum[T, *T]

func EnumSlice

func EnumSlice[T comparable](values []T) *ZodEnum[T, T]

func EnumSlicePtr added in v0.3.0

func EnumSlicePtr[T comparable](values []T) *ZodEnum[T, *T]

type ZodError

type ZodError = issues.ZodError

type ZodErrorTree

type ZodErrorTree = issues.ZodErrorTree

type ZodFile

type ZodFile[T any, R any] = types.ZodFile[T, R]

Public schema type aliases.

type ZodFloat

type ZodFloat[T types.FloatConstraint, R any] = types.ZodFloat[T, R]

Public schema type aliases.

type ZodFormattedError

type ZodFormattedError = issues.ZodFormattedError

type ZodFunction

type ZodFunction[T types.FunctionConstraint] = types.ZodFunction[T]

Public schema type aliases.

type ZodGUID added in v0.5.5

type ZodGUID[T types.StringConstraint] = types.ZodGUID[T]

Public schema type aliases.

type ZodHex added in v0.5.4

type ZodHex[T types.StringConstraint] = types.ZodHex[T]

Public schema type aliases.

type ZodHostname added in v0.5.4

type ZodHostname[T types.StringConstraint] = types.ZodHostname[T]

Public schema type aliases.

type ZodIPv4

type ZodIPv4[T types.StringConstraint] = types.ZodIPv4[T]

Public schema type aliases.

type ZodIPv6

type ZodIPv6[T types.StringConstraint] = types.ZodIPv6[T]

Public schema type aliases.

type ZodInteger

type ZodInteger[T types.IntegerConstraint, R any] = types.ZodInteger[T, R]

Public schema type aliases.

type ZodIntersection

type ZodIntersection[T any, R any] = types.ZodIntersection[T, R]

Public schema type aliases.

type ZodIso added in v0.3.0

type ZodIso[T types.IsoConstraint] = types.ZodIso[T]

Public schema type aliases.

type ZodIssue

type ZodIssue = core.ZodIssue

type ZodJWT added in v0.3.0

type ZodJWT[T types.StringConstraint] = types.ZodJWT[T]

Public schema type aliases.

type ZodKSUID added in v0.3.0

type ZodKSUID[T types.StringConstraint] = types.ZodKSUID[T]

Public schema type aliases.

type ZodLazy

type ZodLazy[T types.LazyConstraint] = types.ZodLazy[T]

Public schema type aliases.

type ZodLiteral

type ZodLiteral[T comparable, R any] = types.ZodLiteral[T, R]

Public schema type aliases.

func Literal

func Literal[T comparable](value T, params ...any) *ZodLiteral[T, T]

func LiteralOf added in v0.3.0

func LiteralOf[T comparable](values []T, params ...any) *ZodLiteral[T, T]

func LiteralPtr added in v0.3.0

func LiteralPtr[T comparable](value T, params ...any) *ZodLiteral[T, *T]

func LiteralPtrOf added in v0.3.0

func LiteralPtrOf[T comparable](values []T, params ...any) *ZodLiteral[T, *T]

type ZodMAC added in v0.5.4

type ZodMAC[T types.StringConstraint] = types.ZodMAC[T]

Public schema type aliases.

type ZodMap

type ZodMap[T any, R any] = types.ZodMap[T, R]

Public schema type aliases.

type ZodNanoID added in v0.3.0

type ZodNanoID[T types.StringConstraint] = types.ZodNanoID[T]

Public schema type aliases.

type ZodNever

type ZodNever[T any, R any] = types.ZodNever[T, R]

Public schema type aliases.

type ZodNil

type ZodNil[T any, R any] = types.ZodNil[T, R]

Public schema type aliases.

type ZodObject

type ZodObject[T any, R any] = types.ZodObject[T, R]

Public schema type aliases.

type ZodRawIssue

type ZodRawIssue = core.ZodRawIssue

type ZodRecord

type ZodRecord[T any, R any] = types.ZodRecord[T, R]

Public schema type aliases.

func Record

func Record[K any, V any](keySchema any, valueSchema core.ZodType[V], paramArgs ...any) *ZodRecord[map[string]V, map[string]V]

func RecordPtr added in v0.3.0

func RecordPtr[K any, V any](keySchema any, valueSchema core.ZodType[V], paramArgs ...any) *ZodRecord[map[string]V, *map[string]V]

type ZodRefineFn added in v0.3.0

type ZodRefineFn[T any] = core.ZodRefineFn[T]

Validation check aliases.

type ZodSet added in v0.5.5

type ZodSet[T comparable, R any] = types.ZodSet[T, R]

Public schema type aliases.

func Set added in v0.5.5

func Set[T comparable](valueSchema any, paramArgs ...any) *ZodSet[T, map[T]struct{}]

func SetPtr added in v0.5.5

func SetPtr[T comparable](valueSchema any, paramArgs ...any) *ZodSet[T, *map[T]struct{}]

type ZodSlice

type ZodSlice[T any, R any] = types.ZodSlice[T, R]

Public schema type aliases.

func Slice

func Slice[T any](elementSchema any, paramArgs ...any) *ZodSlice[T, []T]

func SlicePtr added in v0.3.0

func SlicePtr[T any](elementSchema any, paramArgs ...any) *ZodSlice[T, *[]T]

type ZodString

type ZodString[T types.StringConstraint] = types.ZodString[T]

Public schema type aliases.

type ZodStringBool

type ZodStringBool[T types.StringBoolConstraint] = types.ZodStringBool[T]

Public schema type aliases.

type ZodStruct

type ZodStruct[T any, R any] = types.ZodStruct[T, R]

Public schema type aliases.

func Struct

func Struct[T any](params ...any) *ZodStruct[T, T]

func StructPtr added in v0.3.0

func StructPtr[T any](params ...any) *ZodStruct[T, *T]

type ZodTime added in v0.3.0

type ZodTime[T types.TimeConstraint] = types.ZodTime[T]

Public schema type aliases.

type ZodTuple added in v0.5.4

type ZodTuple[T any, R any] = types.ZodTuple[T, R]

Public schema type aliases.

type ZodType

type ZodType[T any] = core.ZodType[T]

ZodType is a generic alias for core.ZodType for ergonomic use.

type ZodULID added in v0.3.0

type ZodULID[T types.StringConstraint] = types.ZodULID[T]

Public schema type aliases.

type ZodURL added in v0.3.0

type ZodURL[T types.StringConstraint] = types.ZodURL[T]

Public schema type aliases.

type ZodUUID added in v0.3.0

type ZodUUID[T types.StringConstraint] = types.ZodUUID[T]

Public schema type aliases.

type ZodUnion

type ZodUnion[T any, R any] = types.ZodUnion[T, R]

Public schema type aliases.

type ZodUnknown

type ZodUnknown[T any, R any] = types.ZodUnknown[T, R]

Public schema type aliases.

type ZodWhenFn

type ZodWhenFn = core.ZodWhenFn

Validation check aliases.

type ZodXID added in v0.3.0

type ZodXID[T types.StringConstraint] = types.ZodXID[T]

Public schema type aliases.

Directories

Path Synopsis
cmd
gozodgen command
Package main implements the gozodgen code generation tool.
Package main implements the gozodgen code generation tool.
Package coerce provides constructors that enable automatic type coercion before validation.
Package coerce provides constructors that enable automatic type coercion before validation.
Package core provides the foundation contracts for the gozod validation library, including interfaces, types, and constants used throughout the system.
Package core provides the foundation contracts for the gozod validation library, including interfaces, types, and constants used throughout the system.
examples
advanced_lazy command
code_generation command
Package main demonstrates GoZod code generation for zero-overhead struct tag validation.
Package main demonstrates GoZod code generation for zero-overhead struct tag validation.
coerce command
config command
custom_tag command
error_handling command
format command
i18n command
intersection command
object command
primitive command
quickstart command
struct_tags command
Package main demonstrates GoZod struct tag validation usage This example covers the most important features in a simple, practical way.
Package main demonstrates GoZod struct tag validation usage This example covers the most important features in a simple, practical way.
union command
internal
checks
Package checks provides validation check factories for the GoZod validation library.
Package checks provides validation check factories for the GoZod validation library.
engine
Package engine provides the core parsing and validation engine for GoZod schemas.
Package engine provides the core parsing and validation engine for GoZod schemas.
issues
Package issues provides error creation, formatting, and management for GoZod validation.
Package issues provides error creation, formatting, and management for GoZod validation.
utils
Package utils provides internal utility functions for the gozod validation library, including error map conversion, parameter normalization, value origin detection, value comparison, and error path formatting.
Package utils provides internal utility functions for the gozod validation library, including error map conversion, parameter normalization, value origin detection, value comparison, and error path formatting.
Package jsonschema provides JSON Schema conversion for GoZod schemas.
Package jsonschema provides JSON Schema conversion for GoZod schemas.
Package locales provides pre-configured error message formatters for different languages.
Package locales provides pre-configured error message formatters for different languages.
pkg
cloneutil
Package cloneutil centralizes deep-copy behavior for GoZod runtime values and schema internals while preserving library-specific semantics.
Package cloneutil centralizes deep-copy behavior for GoZod runtime values and schema internals while preserving library-specific semantics.
coerce
Package coerce provides type coercion utilities for converting values between different Go types with proper error handling and overflow detection.
Package coerce provides type coercion utilities for converting values between different Go types with proper error handling and overflow detection.
mapx
Package mapx provides type-safe utility functions for working with Go maps.
Package mapx provides type-safe utility functions for working with Go maps.
reflectx
Package reflectx provides reflection utilities for type checking and value manipulation.
Package reflectx provides reflection utilities for type checking and value manipulation.
regex
Package regex provides pre-compiled regular expressions for common data formats.
Package regex provides pre-compiled regular expressions for common data formats.
slicex
Package slicex provides utility functions for working with Go slices.
Package slicex provides utility functions for working with Go slices.
structx
Package structx converts between Go structs and map[string]any.
Package structx converts between Go structs and map[string]any.
tagparser
Package tagparser parses struct-tag validation rules into a reusable representation shared by GoZod runtime code and codegen.
Package tagparser parses struct-tag validation rules into a reusable representation shared by GoZod runtime code and codegen.
transform
Package transform provides string and data transformation utilities such as slugifying strings for URL-friendly formats.
Package transform provides string and data transformation utilities such as slugifying strings for URL-friendly formats.
validate
Package validate provides validation functions for various data types and formats.
Package validate provides validation functions for various data types and formats.
Package types provides public schema implementations for GoZod validation types.
Package types provides public schema implementations for GoZod validation types.

Jump to

Keyboard shortcuts

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