check

package module
v0.0.0-...-cfcbc57 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 10 Imported by: 0

README

check

A validation library for Go that doesn't suck. Inspired by Zod, built for Go.

Why This Exists

Go's standard library is great, but validation gets messy fast. You either write verbose code with lots of if statements, or you grab a library that requires learning struct tags and reflection magic.

check takes a different approach. Define schemas in code with a fluent API. Chain validators together. Get all validation errors at once, not just the first failure. The API looks similar to JavaScript's Zod if you've used that, but it's designed from the ground up for Go.

Install

go get github.com/Alinxus/check

Then import:

import "github.com/Alinxus/check/z"

Quick Start

schema := z.Object(map[string]z.Schema{
    "name":  z.String().Min(3).Max(50),
    "email": z.String().Email(),
    "age":   z.Int().Min(0).Max(150).Optional(),
})

data := map[string]any{
    "name": "Alice",
    "email": "alice@example.com",
}

result, err := schema.Parse(data)
if err != nil {
    fmt.Println(err)
    return
}

// result is validated and type-converted

Core Concepts

Schemas

A schema is a validator. Every schema implements the Schema interface with two methods:

  • Parse(value any) (any, error) - Validate and return the parsed value
  • Validate(value any) []ValidationError - Return all validation errors without failing fast

The key difference from other libraries: Validate returns a slice of all errors, not just the first one. This is more useful in real applications where you want to show users all problems at once.

Chainable API

All schema methods are chainable. They return modified copies of the schema (not mutating the original), so you can safely reuse base schemas:

baseString := z.String().Min(3)
username := baseString.Max(20)     // independent copy
slug := baseString.Max(50).Trim()  // different constraints

This immutability pattern prevents subtle bugs where you accidentally share configuration between schemas.

Type Coercion

When validation is strict about types (which Go is), type coercion schemas bridge the gap. Perfect for form data, query parameters, or environment variables where everything arrives as strings:

z.CoerceInt().Min(0).Max(100)     // "42" becomes int 42
z.CoerceFloat().Min(0)            // "3.14" becomes float64 3.14
z.CoerceBool()                    // "true", "yes", "1", "on" all become true
Transforms

After validation passes, transform the value to something else:

price := z.Transform(z.Float().Min(0), func(v any) (any, error) {
    return fmt.Sprintf("$%.2f", v.(float64)), nil
})

result, _ := price.Parse(19.99)
// result == "$19.99"

Transforms are useful for normalizing data, computing derived values, or converting types.

Schema Types

String

Basic string validation with common checks:

z.String()                          // required string
z.String().Optional()               // can be nil
z.String().Default("fallback")      // nil becomes "fallback"
z.String().Min(3)                   // at least 3 chars
z.String().Max(50)                  // at most 50 chars
z.String().Email()                  // valid email
z.String().URL()                    // valid URL
z.String().UUID()                   // valid UUID v4
z.String().Pattern(regexp, "msg")   // regex match
z.String().Contains("foo")          // must contain substring
z.String().HasPrefix("http")        // must start with
z.String().HasSuffix(".com")        // must end with
z.String().OneOf("a", "b", "c")     // enum
z.String().Trim()                   // trim whitespace before validation
z.String().ToLower()                // lowercase before validation
z.String().ToUpper()                // uppercase before validation
z.String().Custom(func(s string) error { ... })
Int

Integer validation:

z.Int()                    // required integer
z.Int().Min(0)             // >= 0
z.Int().Max(100)           // <= 100
z.Int().Positive()         // > 0
z.Int().Negative()         // < 0
z.Int().NonZero()          // != 0
z.Int().OneOf(1, 2, 3)     // enum
z.Int().Optional()
z.Int().Default(42)
z.Int().Custom(func(n int) error { ... })
Float

Floating point numbers:

z.Float()                  // required float64
z.Float().Min(0.0)
z.Float().Max(1.0)
z.Float().Positive()
z.Float().Negative()
z.Float().Optional()
z.Float().Default(3.14)
z.Float().Custom(func(f float64) error { ... })
Bool

Boolean values:

z.Bool()                   // required boolean
z.Bool().Optional()
z.Bool().Default(false)
Time

Date and time handling with flexible parsing:

z.Time()                             // required, parses RFC3339 strings
z.Time().Optional()
z.Time().Layout("2006-01-02")        // custom time format
z.Time().Layout("2006-01-02", time.RFC3339) // try multiple formats
z.Time().Before(deadline)            // must be before
z.Time().After(startDate)            // must be after
z.Time().Custom(func(t time.Time) error { ... })
Any

Accepts any non-nil value (rarely needed):

z.Any()                    // accepts anything non-nil
z.Any().Optional()         // accepts anything including nil
Array

Validate slice elements:

z.Array(z.String())              // array of strings
z.Array(z.Int().Positive())      // array of positive ints
z.Array(z.String()).MinLength(1) // at least 1 item
z.Array(z.String()).MaxLength(10)// at most 10 items

Errors for array elements include the index:

Validation failed:
  - colors[1]: must be one of [red, green, blue] (got "yellow")
Object

Validate structured data with named fields:

z.Object(map[string]z.Schema{
    "name":  z.String().Min(1),
    "email": z.String().Email(),
    "age":   z.Int().Optional(),
})

Field errors include the field path:

Validation failed:
  - name: must be at least 1 characters
  - email: invalid email format

With nested objects, paths get deeper:

z.Object(map[string]z.Schema{
    "user": z.Object(map[string]z.Schema{
        "address": z.Object(map[string]z.Schema{
            "city": z.String().Min(1),
        }),
    }),
})

Error:

Validation failed:
  - user.address.city: must be at least 1 characters

Strict mode rejects unknown fields (useful for APIs):

z.Object(map[string]z.Schema{
    "name": z.String(),
}).Strict()
Map

Validate dictionaries with key and value constraints:

z.Map(z.String().Min(1), z.Int().Positive())
z.Map(z.String(), z.Any()).MinLength(1).MaxLength(100)
Union

A value matching any one of several schemas:

z.Union(z.String(), z.Int())  // string or int

Parsing Methods

Parse

Validate and return the parsed value. Fails fast on the first error:

result, err := schema.Parse(data)
if err != nil {
    fmt.Println(err)
}
Validate

Collect all errors without failing fast. Useful for showing users all problems at once:

errs := schema.Validate(data)
for _, e := range errs {
    fmt.Printf("%s: %s\n", e.Path, e.Message)
}
ParseJSON

Validate raw JSON bytes:

jsonBytes := []byte(`{"name": "Alice", "email": "alice@example.com"}`)
result, err := z.ParseJSON(schema, jsonBytes)
ParseStruct

Validate data and map it into a Go struct using struct tags:

type User struct {
    Name  string `json:"name"`
    Email string `json:"email"`
}

var user User
err := z.ParseStruct(schema, data, &user)
// user.Name and user.Email are now populated
ParseTyped

Type-safe parsing with generics. No type assertions needed:

name, err := z.ParseTyped[string](z.String().Min(3), "Alice")
// name is string, not any
age, err := z.ParseTyped[int](z.Int().Positive(), 25)
// age is int, not any

Real-World Example

A complete user registration endpoint:

package main

import (
    "fmt"
    "github.com/Alinxus/check/z"
)

var createUserSchema = z.Object(map[string]z.Schema{
    "username": z.String().Min(3).Max(20),
    "email":    z.String().Email(),
    "password": z.String().Min(8),
    "age":      z.Int().Min(13).Max(120).Optional(),
    "role":     z.String().OneOf("user", "moderator").Default("user"),
    "tags":     z.Array(z.String()).MinLength(1).MaxLength(10),
    "address": z.Object(map[string]z.Schema{
        "street": z.String().Min(1),
        "city":   z.String().Min(1),
        "zip":    z.String().Pattern(zipCode, "invalid zip"),
    }).Optional(),
})

func handleCreateUser(data map[string]any) error {
    var user User
    if err := z.ParseStruct(createUserSchema, data, &user); err != nil {
        // err contains all validation failures
        fmt.Println(err)
        return err
    }

    // user is now fully validated and type-safe
    return saveUser(user)
}

Error Messages

Validation errors are designed to be helpful and readable:

Validation failed:
  - username: must be at least 3 characters (got "ab")
  - email: invalid email format
  - age: must be at least 13 (got 10)
  - tags: array must have at least 1 item(s) (got 0)

The ValidationError type gives you access to individual failures:

type ValidationError struct {
    Path    string  // dot-separated path, e.g. "address.city"
    Message string  // human-readable message
    Value   any     // the offending value
}

Design Decisions

No Dependencies

Zero external dependencies. The library only uses Go's standard library. This keeps it simple, fast, and easy to integrate.

Immutability Through Cloning

Every chainable method returns a new schema instance rather than mutating the receiver. This prevents subtle bugs where schemas accidentally share configuration. It's a Go best practice borrowed from functional programming.

All Errors at Once

Most validators stop at the first error. check collects all validation errors so you can show users everything that's wrong at once. This is better UX for forms, APIs, and batch processing.

Type Conversion, Not Coercion

The coerce schemas explicitly convert types (string to int, etc). They don't try to be clever. This makes the behavior predictable.

Go Idioms

The API uses Go conventions:

  • Interfaces for extension
  • Slice of errors instead of wrapped errors
  • Simple, readable code without magic
  • No reflection where it's not needed

Limitations

This library is for validating Go types. It won't:

  • Generate documentation or JSON schemas (future feature maybe)
  • Handle async validators or database lookups (by design)
  • Parse struct tags (intentional - we do code-based schemas)
  • Validate pointers directly (convert to concrete types first)

Contributing

Bug fixes and suggestions are welcome. The goal is to keep this library simple and focused on validation, not to build a kitchen-sink framework.

License

MIT. Use it however you want, commercially or otherwise. See LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseStruct

func ParseStruct(schema Schema, data any, target any) error

ParseStruct validates data against a schema, then maps the validated result into a Go struct. The target must be a pointer to a struct.

Field mapping uses the "json" struct tag (or lowercase field name if no tag).

Usage:

type User struct {
    Name  string   `json:"name"`
    Email string   `json:"email"`
    Age   int      `json:"age"`
    Tags  []string `json:"tags"`
}

var user User
err := check.ParseStruct(schema, data, &user)

func ParseTyped

func ParseTyped[T any](schema Schema, value any) (T, error)

ParseTyped validates a value against a schema and returns a typed result. This avoids the need to type-assert the result of Parse.

Usage:

name, err := check.ParseTyped[string](z.String().Min(3), "Alice")
age, err := check.ParseTyped[int](z.Int().Positive(), 25)
users, err := check.ParseTyped[[]any](z.Array(z.String()), data)

Types

type AnySchema

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

AnySchema accepts any value.

func NewAny

func NewAny() *AnySchema

func (*AnySchema) IsOptional

func (s *AnySchema) IsOptional() bool

func (*AnySchema) Optional

func (s *AnySchema) Optional() *AnySchema

func (*AnySchema) Parse

func (s *AnySchema) Parse(value any) (any, error)

func (*AnySchema) Validate

func (s *AnySchema) Validate(value any) []ValidationError

type ArraySchema

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

ArraySchema validates slices/arrays where each element matches an inner schema.

func NewArray

func NewArray(element Schema) *ArraySchema

func (*ArraySchema) Custom

func (s *ArraySchema) Custom(fn func([]any) error) *ArraySchema

func (*ArraySchema) IsOptional

func (s *ArraySchema) IsOptional() bool

func (*ArraySchema) MaxLength

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

func (*ArraySchema) MinLength

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

func (*ArraySchema) Optional

func (s *ArraySchema) Optional() *ArraySchema

func (*ArraySchema) Parse

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

func (*ArraySchema) Validate

func (s *ArraySchema) Validate(value any) []ValidationError

type BoolSchema

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

BoolSchema validates boolean values.

func NewBool

func NewBool() *BoolSchema

func (*BoolSchema) Default

func (s *BoolSchema) Default(v bool) *BoolSchema

func (*BoolSchema) IsOptional

func (s *BoolSchema) IsOptional() bool

func (*BoolSchema) Optional

func (s *BoolSchema) Optional() *BoolSchema

func (*BoolSchema) Parse

func (s *BoolSchema) Parse(value any) (any, error)

func (*BoolSchema) Validate

func (s *BoolSchema) Validate(value any) []ValidationError

type CoerceBoolSchema

type CoerceBoolSchema struct {
	BoolSchema
}

CoerceBoolSchema wraps BoolSchema but coerces strings to bool before validation.

z.CoerceBool().Parse("true")  // returns true, nil
z.CoerceBool().Parse("1")     // returns true, nil
z.CoerceBool().Parse("false") // returns false, nil
z.CoerceBool().Parse("0")     // returns false, nil

func NewCoerceBool

func NewCoerceBool() *CoerceBoolSchema

func (*CoerceBoolSchema) Default

func (s *CoerceBoolSchema) Default(v bool) *CoerceBoolSchema

func (*CoerceBoolSchema) Optional

func (s *CoerceBoolSchema) Optional() *CoerceBoolSchema

func (*CoerceBoolSchema) Parse

func (s *CoerceBoolSchema) Parse(value any) (any, error)

func (*CoerceBoolSchema) Validate

func (s *CoerceBoolSchema) Validate(value any) []ValidationError

type CoerceFloatSchema

type CoerceFloatSchema struct {
	FloatSchema
}

CoerceFloatSchema wraps FloatSchema but coerces strings to float64 before validation.

z.CoerceFloat().Min(0).Parse("3.14") // returns 3.14, nil

func NewCoerceFloat

func NewCoerceFloat() *CoerceFloatSchema

func (*CoerceFloatSchema) Custom

func (s *CoerceFloatSchema) Custom(fn func(float64) error) *CoerceFloatSchema

func (*CoerceFloatSchema) Default

func (*CoerceFloatSchema) Max

func (*CoerceFloatSchema) Min

func (*CoerceFloatSchema) Negative

func (s *CoerceFloatSchema) Negative() *CoerceFloatSchema

func (*CoerceFloatSchema) Optional

func (s *CoerceFloatSchema) Optional() *CoerceFloatSchema

func (*CoerceFloatSchema) Parse

func (s *CoerceFloatSchema) Parse(value any) (any, error)

func (*CoerceFloatSchema) Positive

func (s *CoerceFloatSchema) Positive() *CoerceFloatSchema

func (*CoerceFloatSchema) Validate

func (s *CoerceFloatSchema) Validate(value any) []ValidationError

type CoerceIntSchema

type CoerceIntSchema struct {
	IntSchema
}

CoerceIntSchema wraps IntSchema but coerces strings and floats to int before validation.

z.CoerceInt().Min(0).Parse("42") // returns 42, nil

func NewCoerceInt

func NewCoerceInt() *CoerceIntSchema

func (*CoerceIntSchema) Custom

func (s *CoerceIntSchema) Custom(fn func(int) error) *CoerceIntSchema

func (*CoerceIntSchema) Default

func (s *CoerceIntSchema) Default(v int) *CoerceIntSchema

func (*CoerceIntSchema) Max

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

func (*CoerceIntSchema) Min

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

func (*CoerceIntSchema) Negative

func (s *CoerceIntSchema) Negative() *CoerceIntSchema

func (*CoerceIntSchema) NonZero

func (s *CoerceIntSchema) NonZero() *CoerceIntSchema

func (*CoerceIntSchema) OneOf

func (s *CoerceIntSchema) OneOf(vals ...int) *CoerceIntSchema

func (*CoerceIntSchema) Optional

func (s *CoerceIntSchema) Optional() *CoerceIntSchema

func (*CoerceIntSchema) Parse

func (s *CoerceIntSchema) Parse(value any) (any, error)

func (*CoerceIntSchema) Positive

func (s *CoerceIntSchema) Positive() *CoerceIntSchema

func (*CoerceIntSchema) Validate

func (s *CoerceIntSchema) Validate(value any) []ValidationError

type FloatSchema

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

FloatSchema validates float64 values.

func NewFloat

func NewFloat() *FloatSchema

func (*FloatSchema) Custom

func (s *FloatSchema) Custom(fn func(float64) error) *FloatSchema

func (*FloatSchema) Default

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

func (*FloatSchema) IsOptional

func (s *FloatSchema) IsOptional() bool

func (*FloatSchema) Max

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

func (*FloatSchema) Min

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

func (*FloatSchema) Negative

func (s *FloatSchema) Negative() *FloatSchema

func (*FloatSchema) Optional

func (s *FloatSchema) Optional() *FloatSchema

func (*FloatSchema) Parse

func (s *FloatSchema) Parse(value any) (any, error)

func (*FloatSchema) Positive

func (s *FloatSchema) Positive() *FloatSchema

func (*FloatSchema) Validate

func (s *FloatSchema) Validate(value any) []ValidationError

type IntSchema

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

IntSchema validates integer values.

func NewInt

func NewInt() *IntSchema

func (*IntSchema) Custom

func (s *IntSchema) Custom(fn func(int) error) *IntSchema

func (*IntSchema) Default

func (s *IntSchema) Default(v int) *IntSchema

func (*IntSchema) IsOptional

func (s *IntSchema) IsOptional() bool

func (*IntSchema) Max

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

func (*IntSchema) Min

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

func (*IntSchema) Negative

func (s *IntSchema) Negative() *IntSchema

func (*IntSchema) NonZero

func (s *IntSchema) NonZero() *IntSchema

func (*IntSchema) OneOf

func (s *IntSchema) OneOf(vals ...int) *IntSchema

func (*IntSchema) Optional

func (s *IntSchema) Optional() *IntSchema

func (*IntSchema) Parse

func (s *IntSchema) Parse(value any) (any, error)

func (*IntSchema) Positive

func (s *IntSchema) Positive() *IntSchema

func (*IntSchema) Validate

func (s *IntSchema) Validate(value any) []ValidationError

type MapSchema

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

MapSchema validates map[string]any where all keys match a key schema and all values match a value schema.

func NewMap

func NewMap(key, value Schema) *MapSchema

func (*MapSchema) IsOptional

func (s *MapSchema) IsOptional() bool

func (*MapSchema) MaxLength

func (s *MapSchema) MaxLength(n int) *MapSchema

func (*MapSchema) MinLength

func (s *MapSchema) MinLength(n int) *MapSchema

func (*MapSchema) Optional

func (s *MapSchema) Optional() *MapSchema

func (*MapSchema) Parse

func (s *MapSchema) Parse(value any) (any, error)

func (*MapSchema) Validate

func (s *MapSchema) Validate(value any) []ValidationError

type ObjectSchema

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

ObjectSchema validates map[string]any objects with named fields.

func NewObject

func NewObject(fields map[string]Schema) *ObjectSchema

func (*ObjectSchema) IsOptional

func (s *ObjectSchema) IsOptional() bool

func (*ObjectSchema) Optional

func (s *ObjectSchema) Optional() *ObjectSchema

func (*ObjectSchema) Parse

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

func (*ObjectSchema) Strict

func (s *ObjectSchema) Strict() *ObjectSchema

Strict rejects objects with keys not defined in the schema.

func (*ObjectSchema) Validate

func (s *ObjectSchema) Validate(value any) []ValidationError

type Schema

type Schema interface {
	// Parse validates and returns the (possibly transformed) value, or an error.
	Parse(value any) (any, error)

	// Validate returns all validation errors (not just the first).
	Validate(value any) []ValidationError

	// IsOptional reports whether this schema accepts nil values.
	IsOptional() bool
}

Schema is the core interface all schemas implement.

type StringSchema

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

StringSchema validates string values.

func NewString

func NewString() *StringSchema

NewString creates a new StringSchema.

func (*StringSchema) Contains

func (s *StringSchema) Contains(sub string) *StringSchema

func (*StringSchema) Custom

func (s *StringSchema) Custom(fn func(string) error) *StringSchema

func (*StringSchema) Default

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

func (*StringSchema) Email

func (s *StringSchema) Email() *StringSchema

func (*StringSchema) HasPrefix

func (s *StringSchema) HasPrefix(pre string) *StringSchema

func (*StringSchema) HasSuffix

func (s *StringSchema) HasSuffix(suf string) *StringSchema

func (*StringSchema) IsOptional

func (s *StringSchema) IsOptional() bool

func (*StringSchema) Max

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

func (*StringSchema) Min

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

func (*StringSchema) OneOf

func (s *StringSchema) OneOf(values ...string) *StringSchema

func (*StringSchema) Optional

func (s *StringSchema) Optional() *StringSchema

func (*StringSchema) Parse

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

func (*StringSchema) Pattern

func (s *StringSchema) Pattern(re *regexp.Regexp, msg string) *StringSchema

func (*StringSchema) ToLower

func (s *StringSchema) ToLower() *StringSchema

func (*StringSchema) ToUpper

func (s *StringSchema) ToUpper() *StringSchema

func (*StringSchema) Trim

func (s *StringSchema) Trim() *StringSchema

func (*StringSchema) URL

func (s *StringSchema) URL() *StringSchema

func (*StringSchema) UUID

func (s *StringSchema) UUID() *StringSchema

func (*StringSchema) Validate

func (s *StringSchema) Validate(value any) []ValidationError

type TimeSchema

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

TimeSchema validates time.Time values. It can also parse time strings using configurable layouts (defaults to RFC3339).

func NewTime

func NewTime() *TimeSchema

func (*TimeSchema) After

func (s *TimeSchema) After(t time.Time) *TimeSchema

After requires the time to be after the given time.

func (*TimeSchema) Before

func (s *TimeSchema) Before(t time.Time) *TimeSchema

Before requires the time to be before the given time.

func (*TimeSchema) Custom

func (s *TimeSchema) Custom(fn func(time.Time) error) *TimeSchema

Custom adds a custom validation function.

func (*TimeSchema) Default

func (s *TimeSchema) Default(v time.Time) *TimeSchema

func (*TimeSchema) IsOptional

func (s *TimeSchema) IsOptional() bool

func (*TimeSchema) Layout

func (s *TimeSchema) Layout(layouts ...string) *TimeSchema

Layout sets the time layout(s) used when parsing strings. Replaces the default RFC3339. Multiple layouts are tried in order.

func (*TimeSchema) Optional

func (s *TimeSchema) Optional() *TimeSchema

func (*TimeSchema) Parse

func (s *TimeSchema) Parse(value any) (any, error)

func (*TimeSchema) Validate

func (s *TimeSchema) Validate(value any) []ValidationError

type TransformSchema

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

Transform adds a generic transformation step to any schema. The transform runs after validation succeeds.

func Transform

func Transform(inner Schema, fn func(any) (any, error)) *TransformSchema

Transform wraps a schema and applies a transformation after successful validation.

// Parse a string, then convert to uppercase
upper := check.Transform(check.NewString(), func(v any) (any, error) {
    return strings.ToUpper(v.(string)), nil
})

func (*TransformSchema) IsOptional

func (s *TransformSchema) IsOptional() bool

func (*TransformSchema) Parse

func (s *TransformSchema) Parse(value any) (any, error)

func (*TransformSchema) Validate

func (s *TransformSchema) Validate(value any) []ValidationError

type UnionSchema

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

UnionSchema validates that a value matches at least one of the given schemas.

func NewUnion

func NewUnion(schemas ...Schema) *UnionSchema

func (*UnionSchema) IsOptional

func (s *UnionSchema) IsOptional() bool

func (*UnionSchema) Optional

func (s *UnionSchema) Optional() *UnionSchema

func (*UnionSchema) Parse

func (s *UnionSchema) Parse(value any) (any, error)

func (*UnionSchema) Validate

func (s *UnionSchema) Validate(value any) []ValidationError

type ValidationError

type ValidationError struct {
	Path    string // dot-separated path, e.g. "address.city"
	Message string // human-readable message
	Value   any    // the offending value
}

ValidationError represents a single validation failure.

func (ValidationError) Error

func (e ValidationError) Error() string

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors is a collection of validation errors that implements error.

func (ValidationErrors) Error

func (ve ValidationErrors) Error() string

Directories

Path Synopsis
z
Package z provides the public API for Check schema validation.
Package z provides the public API for Check schema validation.

Jump to

Keyboard shortcuts

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