validate

package
v0.0.2-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package validate is a hex-namespaced entrypoint for github.com/Oudwins/zog, a Zod-style schema parser + validator.

Zog is already idiomatic Go and the wrapper is intentionally thin — hex re-exports the common builder functions and issue types so consumers get a hex-consistent import path (and one place to swap the library later) but do not lose zog's expressive API. For advanced features import the underlying package directly.

The one hex-specific helper is ToError, which converts a zog issue list into a hex/errors typed error with CodeInvalidArgument, so API handlers can map validation failures to 400 responses uniformly.

Example:

var userSchema = validate.Struct(validate.Shape{
    "email": validate.String().Required().Email(),
    "age":   validate.Int().Required().GTE(18),
})

type User struct {
    Email string
    Age   int
}

var u User
if issues := userSchema.Parse(input, &u); issues != nil {
    return validate.ToError(issues)  // *errors.Error with CodeInvalidArgument
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(opts ...z.SchemaOption) *z.BoolSchema[bool]

Bool creates a schema for bool values.

func Float

func Float(opts ...z.SchemaOption) *z.NumberSchema[float64]

Float creates a schema for float64 values.

func Int

func Int(opts ...z.SchemaOption) *z.NumberSchema[int]

Int creates a schema for int values.

func Int64

func Int64(opts ...z.SchemaOption) *z.NumberSchema[int64]

Int64 creates a schema for int64 values.

func Slice

func Slice(schema z.ZogSchema, opts ...z.SchemaOption) *z.SliceSchema

Slice creates a schema for a slice whose elements validate against schema.

func String

func String(opts ...z.SchemaOption) *z.StringSchema[string]

String creates a schema for string values.

func Struct

func Struct(shape Shape) *z.StructSchema

Struct creates a schema for a struct described by shape.

func ToError

func ToError(issues Issues) error

ToError converts a zog issue list into a hex/errors typed error carrying CodeInvalidArgument. Multiple issues are joined with a semicolon so the resulting Error message reads naturally in logs; consumers who want per-field detail should walk the raw Issues.

Returns nil if issues is empty — callers can:

if err := validate.ToError(schema.Parse(in, &out)); err != nil {
    return err
}

Types

type Issue

type Issue = z.ZogIssue

Issue is a single validation failure with path and message.

type Issues

type Issues = z.ZogIssueList

Issues is a slice of validation failures returned by Parse/Validate.

type Schema

type Schema = z.ZogSchema

Schema is the interface every validator implements.

type Shape

type Shape = z.Shape

Shape describes a struct schema — a map of field names to per-field schemas.

Jump to

Keyboard shortcuts

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