zod

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package zod provides a Go adapter for the npm "zod" schema validation library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArraySchema

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

func Array

func Array(element Schema) *ArraySchema

func (*ArraySchema) Max

func (s *ArraySchema) Max(n int) *ArraySchema

func (*ArraySchema) Min

func (s *ArraySchema) Min(n int) *ArraySchema

func (*ArraySchema) Optional

func (s *ArraySchema) Optional() *ArraySchema

func (*ArraySchema) Parse

func (s *ArraySchema) Parse(v any) (any, error)

func (*ArraySchema) SafeParse

func (s *ArraySchema) SafeParse(v any) ParseResult

type BooleanSchema

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

func Boolean

func Boolean() *BooleanSchema

func (*BooleanSchema) Optional

func (s *BooleanSchema) Optional() *BooleanSchema

func (*BooleanSchema) Parse

func (s *BooleanSchema) Parse(v any) (any, error)

func (*BooleanSchema) SafeParse

func (s *BooleanSchema) SafeParse(v any) ParseResult

type EnumSchema

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

func Enum

func Enum(values ...string) *EnumSchema

func (*EnumSchema) Optional

func (s *EnumSchema) Optional() *EnumSchema

func (*EnumSchema) Parse

func (s *EnumSchema) Parse(v any) (any, error)

func (*EnumSchema) SafeParse

func (s *EnumSchema) SafeParse(v any) ParseResult

type NumberSchema

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

func Number

func Number() *NumberSchema

func (*NumberSchema) Default

func (s *NumberSchema) Default(v float64) *NumberSchema

func (*NumberSchema) Int

func (s *NumberSchema) Int() *NumberSchema

func (*NumberSchema) Max

func (s *NumberSchema) Max(n float64) *NumberSchema

func (*NumberSchema) Min

func (s *NumberSchema) Min(n float64) *NumberSchema

func (*NumberSchema) Optional

func (s *NumberSchema) Optional() *NumberSchema

func (*NumberSchema) Parse

func (s *NumberSchema) Parse(v any) (any, error)

func (*NumberSchema) SafeParse

func (s *NumberSchema) SafeParse(v any) ParseResult

type ObjectSchema

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

func Object

func Object(shape map[string]Schema) *ObjectSchema

func (*ObjectSchema) Optional

func (s *ObjectSchema) Optional() *ObjectSchema

func (*ObjectSchema) Parse

func (s *ObjectSchema) Parse(v any) (any, error)

func (*ObjectSchema) SafeParse

func (s *ObjectSchema) SafeParse(v any) ParseResult

type ParseResult

type ParseResult struct {
	Success bool
	Data    any
	Error   *ZodError
}

ParseResult holds the result of a Parse or SafeParse operation.

type Schema

type Schema interface {
	Parse(v any) (any, error)
	SafeParse(v any) ParseResult
}

Schema is the interface all zod schemas implement.

type StringSchema

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

func String

func String() *StringSchema

func (*StringSchema) Default

func (s *StringSchema) Default(v string) *StringSchema

func (*StringSchema) Email

func (s *StringSchema) Email() *StringSchema

func (*StringSchema) Max

func (s *StringSchema) Max(n int) *StringSchema

func (*StringSchema) Min

func (s *StringSchema) Min(n int) *StringSchema

func (*StringSchema) Optional

func (s *StringSchema) Optional() *StringSchema

func (*StringSchema) Parse

func (s *StringSchema) Parse(v any) (any, error)

func (*StringSchema) Regex

func (s *StringSchema) Regex(r *regexp.Regexp) *StringSchema

func (*StringSchema) SafeParse

func (s *StringSchema) SafeParse(v any) ParseResult

func (*StringSchema) Url

func (s *StringSchema) Url() *StringSchema

type ZodError

type ZodError struct {
	Issues []ZodIssue
}

ZodError represents a validation error.

func (*ZodError) Error

func (e *ZodError) Error() string

type ZodIssue

type ZodIssue struct {
	Path    []string
	Message string
	Code    string
}

ZodIssue represents a single validation issue.

Jump to

Keyboard shortcuts

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