Documentation
¶
Overview ¶
Package validate provides composable validation helpers for Go with fluent builders, rule tags, struct validation, domain format validators, and optional message translation support.
Index ¶
- Constants
- Variables
- func CheckTagContext(ctx context.Context, v *Validate, tag string, value any) error
- func CheckTagContextWithOpts(ctx context.Context, v *Validate, tag string, value any, opts CompileOpts) error
- func CheckTagWithOpts(v *Validate, tag string, value any, opts CompileOpts) error
- func FromTag(v *Validate, tag string) (func(any) error, error)
- func FromTagWithOpts(v *Validate, tag string, opts CompileOpts) (func(any) error, error)
- func ValidateStruct(v *Validate, s any) error
- func ValidateStructContext(ctx context.Context, v *Validate, s any) error
- func ValidateStructContextWithOpts(ctx context.Context, v *Validate, s any, opts ValidateOpts) error
- func ValidateStructWithOpts(v *Validate, s any, opts ValidateOpts) error
- type ArrayBuilder
- type BoolBuilder
- type CompileOpts
- type ContextRuleCompiler
- type ContextValidatorFunc
- type CustomTypeBuilder
- type Errors
- type FloatBuilder
- type IntBuilder
- type Kind
- type MapBuilder
- type Rule
- type RuleCompiler
- type SimpleTranslator
- type SliceBuilder
- type StringBuilder
- type StructRuleCompiler
- type StructRuleContext
- type StructRuleFunc
- type TimeBuilder
- type Translator
- type TypeValidator
- type TypeValidatorFactory
- type Validate
- type ValidateOpts
- type ValidatorFunc
Constants ¶
const ( // String validation kinds KString = types.KString KLength = types.KLength KMinLength = types.KMinLength KMaxLength = types.KMaxLength KRegex = types.KRegex KOneOf = types.KOneOf KMinRunes = types.KMinRunes KMaxRunes = types.KMaxRunes KNonEmpty = types.KNonEmpty KContains = types.KContains KNotContains = types.KNotContains KPrefix = types.KPrefix KSuffix = types.KSuffix KURL = types.KURL KHostname = types.KHostname KIP = types.KIP KIPv4 = types.KIPv4 KIPv6 = types.KIPv6 KCIDR = types.KCIDR KASCII = types.KASCII KAlpha = types.KAlpha KAlnum = types.KAlnum // Generic modifiers KOmitempty = types.KOmitempty KRequired = types.KRequired // Integer validation kinds KInt = types.KInt KInt64 = types.KInt64 KMinInt = types.KMinInt KMaxInt = types.KMaxInt KFloat = types.KFloat KMinNumber = types.KMinNumber KMaxNumber = types.KMaxNumber KGreaterThan = types.KGreaterThan KGreaterThanEqual = types.KGreaterThanEqual KLessThan = types.KLessThan KLessThanEqual = types.KLessThanEqual KBetween = types.KBetween KPositive = types.KPositive KNonNegative = types.KNonNegative KFinite = types.KFinite // Slice validation kinds KSlice = types.KSlice KSliceLength = types.KSliceLength KMinSliceLength = types.KMinSliceLength KMaxSliceLength = types.KMaxSliceLength KForEach = types.KForEach KSliceUnique = types.KSliceUnique KSliceContains = types.KSliceContains // Array validation kinds KArray = types.KArray KArrayLength = types.KArrayLength KMinArrayLength = types.KMinArrayLength KMaxArrayLength = types.KMaxArrayLength KArrayForEach = types.KArrayForEach KArrayUnique = types.KArrayUnique KArrayContains = types.KArrayContains // Map validation kinds KMap = types.KMap KMapLength = types.KMapLength KMinMapKeys = types.KMinMapKeys KMaxMapKeys = types.KMaxMapKeys KMapKeys = types.KMapKeys KMapValues = types.KMapValues // Boolean validation kinds KBool = types.KBool KBoolTrue = types.KBoolTrue KBoolFalse = types.KBoolFalse // Time validation kinds KTime = types.KTime KTimeNotZero = types.KTimeNotZero KTimeBefore = types.KTimeBefore KTimeAfter = types.KTimeAfter KTimeBetween = types.KTimeBetween )
Re-export commonly used rule kinds
Variables ¶
var ( NewSimpleTranslator = translator.NewSimpleTranslator DefaultEnglishTranslations = translator.DefaultEnglishTranslations MergeTranslations = translator.MergeTranslations RegisterDefaultEnglishTranslations = translator.RegisterDefaultEnglishTranslations JSONFieldName = structvalidator.JSONFieldName )
Re-export translator functions
var ( NewRule = types.NewRule RegisterRule = types.RegisterRule RegisterGlobalType = types.RegisterGlobalType )
Re-export types functions
Functions ¶
func CheckTagContext ¶ added in v3.0.5
CheckTagContext compiles a tag and validates a single value with context.
func CheckTagContextWithOpts ¶ added in v3.0.5
func CheckTagContextWithOpts(ctx context.Context, v *Validate, tag string, value any, opts CompileOpts) error
CheckTagContextWithOpts compiles a tag and validates a single value with context and compile options using v (or a fresh instance).
func CheckTagWithOpts ¶ added in v3.0.5
func CheckTagWithOpts(v *Validate, tag string, value any, opts CompileOpts) error
CheckTagWithOpts compiles a tag and validates a single value with compile options using v (or a fresh instance).
func FromTagWithOpts ¶ added in v3.0.5
FromTagWithOpts compiles a single tag string using v (or a fresh instance) with compile options.
func ValidateStruct ¶ added in v3.0.3
ValidateStruct validates a struct using v (or a fresh instance).
func ValidateStructContext ¶ added in v3.0.5
ValidateStructContext validates a struct with context using v (or a fresh instance).
func ValidateStructContextWithOpts ¶ added in v3.0.5
func ValidateStructContextWithOpts(ctx context.Context, v *Validate, s any, opts ValidateOpts) error
ValidateStructContextWithOpts validates a struct with context using v (or a fresh instance) and struct validation options.
func ValidateStructWithOpts ¶ added in v3.0.5
func ValidateStructWithOpts(v *Validate, s any, opts ValidateOpts) error
ValidateStructWithOpts validates a struct using v (or a fresh instance) with struct validation options.
Types ¶
type ArrayBuilder ¶ added in v3.0.5
type ArrayBuilder = glue.ArrayBuilder
type BoolBuilder ¶
type BoolBuilder = glue.BoolBuilder
type CompileOpts ¶ added in v3.0.5
type CompileOpts = types.CompileOpts
type ContextRuleCompiler ¶ added in v3.0.5
type ContextRuleCompiler = types.ContextRuleCompiler
type ContextValidatorFunc ¶ added in v3.0.5
type ContextValidatorFunc = types.ContextValidatorFunc
func FromTagContext ¶ added in v3.0.5
func FromTagContext(v *Validate, tag string) (ContextValidatorFunc, error)
FromTagContext compiles a single tag string into a context-aware validator using v (or a fresh instance).
func FromTagContextWithOpts ¶ added in v3.0.5
func FromTagContextWithOpts(v *Validate, tag string, opts CompileOpts) (ContextValidatorFunc, error)
FromTagContextWithOpts compiles a single tag string into a context-aware validator using v (or a fresh instance) with compile options.
type CustomTypeBuilder ¶ added in v3.0.3
type CustomTypeBuilder = glue.CustomTypeBuilder
type FloatBuilder ¶ added in v3.0.5
type FloatBuilder = glue.FloatBuilder
type IntBuilder ¶
type IntBuilder = glue.IntBuilder
type MapBuilder ¶ added in v3.0.5
type MapBuilder = glue.MapBuilder
type RuleCompiler ¶ added in v3.0.5
type RuleCompiler = types.RuleCompiler
type SimpleTranslator ¶ added in v3.0.4
type SimpleTranslator = translator.SimpleTranslator
type SliceBuilder ¶
type SliceBuilder = glue.SliceBuilder
type StringBuilder ¶
type StringBuilder = glue.StringBuilder
type StructRuleCompiler ¶ added in v3.0.5
type StructRuleCompiler = core.StructRuleCompiler
type StructRuleContext ¶ added in v3.0.5
type StructRuleContext = core.StructRuleContext
type StructRuleFunc ¶ added in v3.0.5
type StructRuleFunc = core.StructRuleFunc
type TimeBuilder ¶ added in v3.0.5
type TimeBuilder = glue.TimeBuilder
type Translator ¶ added in v3.0.4
type Translator = translator.Translator
Re-export translator package
type TypeValidator ¶ added in v3.0.5
type TypeValidator = types.TypeValidator
type TypeValidatorFactory ¶ added in v3.0.5
type TypeValidatorFactory = types.TypeValidatorFactory
type Validate ¶
Re-export types for a developer-friendly root facade.
func New ¶
func New() *Validate
New returns a Validate configured with sensible defaults.
Defaults: - Installs default English translations via SimpleTranslator. - Registers built-in plugins (domain, email, ulid, uuid) via blank imports.
func NewBare ¶
func NewBare() *Validate
NewBare returns a Validate without installing a default translator. Useful for advanced setups that manage translations differently.
func NewWithTranslator ¶
func NewWithTranslator(tr translator.Translator) *Validate
NewWithTranslator returns a Validate configured with the provided translator while keeping other defaults.
type ValidateOpts ¶ added in v3.0.5
type ValidateOpts = core.ValidateOpts
type ValidatorFunc ¶ added in v3.0.4
type ValidatorFunc = types.ValidatorFunc
Directories
¶
| Path | Synopsis |
|---|---|
|
Package core provides the main validation engine and fluent builder APIs.
|
Package core provides the main validation engine and fluent builder APIs. |
|
Package errors provides error types and error handling utilities for validation.
|
Package errors provides error types and error handling utilities for validation. |
|
Package examples provides examples for the validate package.
|
Package examples provides examples for the validate package. |
|
internal
|
|
|
Package structvalidator provides struct validation functionality using reflection.
|
Package structvalidator provides struct validation functionality using reflection. |
|
Package translator provides internationalization support for validation messages.
|
Package translator provides internationalization support for validation messages. |
|
Package types provides the core validation engine types and rule system.
|
Package types provides the core validation engine types and rule system. |
|
Package validators provides legacy validation helpers and plugin architecture.
|
Package validators provides legacy validation helpers and plugin architecture. |
|
domain
Package domain registers universal zero-dependency string format validators.
|
Package domain registers universal zero-dependency string format validators. |
|
email
Package email provides email address validation as a plugin.
|
Package email provides email address validation as a plugin. |
|
ulid
Package ulid provides ULID validation as a plugin.
|
Package ulid provides ULID validation as a plugin. |
|
uuid
Package uuid provides UUID validation as a plugin.
|
Package uuid provides UUID validation as a plugin. |