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 ¶
- type Config
- type FieldSchema
- type Schema
- type ValidationPlugin
- func (p *ValidationPlugin) Commands() []plugin.Command
- func (p *ValidationPlugin) Dependencies() []plugin.Dependency
- func (p *ValidationPlugin) GetConfig() *Config
- func (p *ValidationPlugin) Init() error
- func (p *ValidationPlugin) Name() string
- func (p *ValidationPlugin) OnHook(hook plugin.Hook, ctx map[string]interface{}) error
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 Schema ¶
type Schema struct {
Name string `json:"name"`
Fields map[string]FieldSchema `json:"fields"`
}
Schema represents a validation schema definition.
type ValidationPlugin ¶
type ValidationPlugin struct {
// contains filtered or unexported fields
}
ValidationPlugin provides form validation capabilities.
func (*ValidationPlugin) Commands ¶
func (p *ValidationPlugin) Commands() []plugin.Command
Commands returns custom CLI commands.
func (*ValidationPlugin) Dependencies ¶
func (p *ValidationPlugin) Dependencies() []plugin.Dependency
Dependencies returns required dependencies.
func (*ValidationPlugin) GetConfig ¶
func (p *ValidationPlugin) GetConfig() *Config
GetConfig returns the current configuration.
func (*ValidationPlugin) Init ¶
func (p *ValidationPlugin) Init() error
Init initializes the validation plugin.
func (*ValidationPlugin) Name ¶
func (p *ValidationPlugin) Name() string
Name returns the plugin name.
Click to show internal directories.
Click to hide internal directories.