Skip to content
Node: z.object({...})github.com/sahilkhaire/gox/validate

Schema.Object

Overview

Object builds a schema from field definitions.

If you are coming from Node.js, the closest pattern is z.object({...}).

Method on Schema — call it on a value of that type after constructing or receiving one from a constructor.

Signature

go
func Object(fields map[string]Field) Schema

Compare: Node.js · Standard Go · gox

js
z.object({ name: z.string() });
go
field := validate.String().Email() // fluent schema builder
go
import "github.com/sahilkhaire/gox/validate"

sch := validate.Object(map[string]validate.Field{"name": validate.String().Required()})

Example

go
import "github.com/sahilkhaire/gox/validate"

sch := validate.Object(map[string]validate.Field{"name": validate.String().Required()})

Tips

Obtain a Schema value first (see constructors on the package overview), then call Object.

Standard library alternative

Use the standard library directly:

go
field := validate.String().Email() // fluent schema builder

Back to validate package overview

MIT Licensed · Built for Node.js developers moving to Go