validation

package
v0.1.41 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package validation provides form validation for GoSPA projects. Uses Valibot on the client-side (~1.5KB gzipped) and Go validator on server-side.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// SchemasDir is where validation schemas are stored.
	SchemasDir string `yaml:"schemas_dir" json:"schemasDir"`

	// OutputDir is where generated validation code is written.
	OutputDir string `yaml:"output_dir" json:"outputDir"`

	// GenerateTypes generates TypeScript types from schemas.
	GenerateTypes bool `yaml:"generate_types" json:"generateTypes"`

	// GenerateServer generates Go server-side validation.
	GenerateServer bool `yaml:"generate_server" json:"generateServer"`

	// GenerateClient generates Valibot client-side validation.
	GenerateClient bool `yaml:"generate_client" json:"generateClient"`

	// StrictMode enables strict validation (no unknown fields).
	StrictMode bool `yaml:"strict_mode" json:"strictMode"`

	// CustomValidators is a list of custom validator names.
	CustomValidators []string `yaml:"custom_validators" json:"customValidators"`
}

Config holds validation plugin configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default validation configuration.

type FieldSchema

type FieldSchema struct {
	Type     string `json:"type"`     // string, number, boolean, date, email, url, uuid, etc.
	Required bool   `json:"required"` // whether field is required
	Min      any    `json:"min"`      // minimum value (number) or length (string)
	Max      any    `json:"max"`      // maximum value (number) or length (string)
	Pattern  string `json:"pattern"`  // regex pattern for strings
	Message  string `json:"message"`  // custom error message
	Default  any    `json:"default"`  // default value
}

FieldSchema represents a field in a validation schema.

type Plugin added in v0.1.23

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

Plugin provides form validation capabilities.

func New

func New(cfg *Config) *Plugin

New creates a new Validation plugin.

func (*Plugin) Commands added in v0.1.23

func (p *Plugin) Commands() []plugin.Command

Commands returns custom CLI commands.

func (*Plugin) Dependencies added in v0.1.23

func (p *Plugin) Dependencies() []plugin.Dependency

Dependencies returns required dependencies.

func (*Plugin) GetConfig added in v0.1.23

func (p *Plugin) GetConfig() *Config

GetConfig returns the current configuration.

func (*Plugin) Init added in v0.1.23

func (p *Plugin) Init() error

Init initializes the validation plugin.

func (*Plugin) Name added in v0.1.23

func (p *Plugin) Name() string

Name returns the plugin name.

func (*Plugin) OnHook added in v0.1.23

func (p *Plugin) OnHook(hook plugin.Hook, ctx map[string]interface{}) error

OnHook handles lifecycle hooks.

type Schema

type Schema struct {
	Name   string                 `json:"name"`
	Fields map[string]FieldSchema `json:"fields"`
}

Schema represents a validation schema definition.

Jump to

Keyboard shortcuts

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