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) SchemaCompare: Node.js · Standard Go · gox
js
z.object({ name: z.string() });go
field := validate.String().Email() // fluent schema buildergo
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