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 ¶
- func Bool(opts ...z.SchemaOption) *z.BoolSchema[bool]
- func Float(opts ...z.SchemaOption) *z.NumberSchema[float64]
- func Int(opts ...z.SchemaOption) *z.NumberSchema[int]
- func Int64(opts ...z.SchemaOption) *z.NumberSchema[int64]
- func Slice(schema z.ZogSchema, opts ...z.SchemaOption) *z.SliceSchema
- func String(opts ...z.SchemaOption) *z.StringSchema[string]
- func Struct(shape Shape) *z.StructSchema
- func ToError(issues Issues) error
- type Issue
- type Issues
- type Schema
- type Shape
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 ¶
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 Issues ¶
type Issues = z.ZogIssueList
Issues is a slice of validation failures returned by Parse/Validate.