Documentation
¶
Index ¶
- Variables
- func WithSchema(schema *Schema, field Field)
- type ArrayField
- func (f *ArrayField[T]) AddTransformer(transformer Transformer[interface{}])
- func (f *ArrayField[T]) AppendValidators(validators []Validator)
- func (f *ArrayField[T]) Assign(data map[string]interface{}, schema *Schema) error
- func (f *ArrayField[T]) Description() string
- func (f *ArrayField[T]) Name() string
- func (f *ArrayField[T]) SetDefaultValue(defaultValue interface{})
- func (f *ArrayField[T]) SetDescription(description string)
- func (f *ArrayField[T]) Validate(schema *Schema) error
- func (f *ArrayField[T]) Value() interface{}
- type ContentTypeParsing
- type ConvertField
- func (f *ConvertField[From, To]) AddTransformer(transformer Transformer[To])
- func (f *ConvertField[From, To]) AppendValidators(validators []Validator)
- func (f *ConvertField[From, To]) Assign(data map[string]interface{}, schema *Schema) error
- func (f *ConvertField[From, To]) Description() string
- func (f *ConvertField[From, To]) Name() string
- func (f *ConvertField[From, To]) SetDefaultValue(defaultValue To)
- func (f *ConvertField[From, To]) SetDescription(description string)
- func (f *ConvertField[From, To]) Validate(schema *Schema) error
- func (f *ConvertField[From, To]) Value() interface{}
- type ConvertPointerField
- func (f *ConvertPointerField[From, To]) AddTransformer(transformer Transformer[To])
- func (f *ConvertPointerField[From, To]) AppendValidators(validators []Validator)
- func (f *ConvertPointerField[From, To]) Assign(data map[string]interface{}, schema *Schema) error
- func (f *ConvertPointerField[From, To]) Description() string
- func (f *ConvertPointerField[From, To]) Name() string
- func (f *ConvertPointerField[From, To]) SetDefaultValue(defaultValue To)
- func (f *ConvertPointerField[From, To]) SetDescription(description string)
- func (f *ConvertPointerField[From, To]) Validate(schema *Schema) error
- func (f *ConvertPointerField[From, To]) Value() interface{}
- type DefaultOption
- type DefaultValueSetter
- type DescriptionOption
- type Errors
- type Field
- func Array[T any](name string, ptr interface{}, opts ...Option) Field
- func Convert[From, To any](name string, ptr *To, convert func(From) (*To, error), opts ...Option) Field
- func ConvertPointer[From, To any](name string, ptr **To, convert func(From) (*To, error), opts ...Option) Field
- func HTTPMap[K comparable, V any](name string, ptr *map[K]V, opts ...Option) Field
- func Map[K comparable, V any](name string, ptr *map[K]V, opts ...Option) Field
- func NestedMap[K comparable, V any](name string, ptr *map[K]V, opts ...Option) Field
- func Pointer[T any](name string, ptr **T, opts ...Option) Field
- func Slice[T any](name string, ptr *[]T, opts ...Option) Field
- func Struct[T any](name string, ptr *T, opts ...Option) Field
- func Union(name string, ptr interface{}, ...) Field
- func Value[T any](name string, ptr *T, opts ...Option) Field
- func ValueWithoutAssign[T any](name string, opts ...Option) Field
- type FieldError
- type HTTPMapCallbackOption
- type HTTPMapField
- func (f *HTTPMapField[K, V]) AppendValidators(validators []Validator)
- func (f *HTTPMapField[K, V]) Assign(data map[string]interface{}, schema *Schema) error
- func (f *HTTPMapField[K, V]) Description() string
- func (f *HTTPMapField[K, V]) Name() string
- func (f *HTTPMapField[K, V]) SetCallback(callback func(*Schema, *V))
- func (f *HTTPMapField[K, V]) SetDefaultValue(defaultValue map[K]V)
- func (f *HTTPMapField[K, V]) SetDescription(description string)
- func (f *HTTPMapField[K, V]) Validate(schema *Schema) error
- func (f *HTTPMapField[K, V]) Value() interface{}
- type HTTPRequestOption
- type MapField
- func (f *MapField[K, V]) AppendValidators(validators []Validator)
- func (f *MapField[K, V]) Assign(data map[string]interface{}, schema *Schema) error
- func (f *MapField[K, V]) Description() string
- func (f *MapField[K, V]) Name() string
- func (f *MapField[K, V]) SetCallback(callback func(*Schema, K, V))
- func (f *MapField[K, V]) SetDefaultValue(defaultValue map[K]V)
- func (f *MapField[K, V]) SetDescription(description string)
- func (f *MapField[K, V]) Validate(schema *Schema) error
- func (f *MapField[K, V]) Value() interface{}
- type NestedMapField
- func (f *NestedMapField[K, V]) AppendValidators(validators []Validator)
- func (f *NestedMapField[K, V]) Assign(data map[string]interface{}, schema *Schema) error
- func (f *NestedMapField[K, V]) Description() string
- func (f *NestedMapField[K, V]) Name() string
- func (f *NestedMapField[K, V]) SetCallback(callback func(*Schema, K, V))
- func (f *NestedMapField[K, V]) SetDefaultValue(defaultValue map[K]V)
- func (f *NestedMapField[K, V]) SetDescription(description string)
- func (f *NestedMapField[K, V]) Validate(schema *Schema) error
- func (f *NestedMapField[K, V]) Value() interface{}
- type Option
- func WithDefault[T any](defaultValue T) Option
- func WithDescription(description string) Option
- func WithHTTPMapCallback[K comparable, V any](callback func(*Schema, *V)) Option
- func WithSubSchema[T any](callback func(*Schema, *T)) Option
- func WithSubSchemaMap[K comparable, V any](callback func(*Schema, K, V)) Option
- func WithTransformers[T any](transformers ...Transformer[T]) Option
- func WithValidators(validators ...Validator) Option
- type PointerField
- func (f *PointerField[T]) AddTransformer(transformer Transformer[T])
- func (f *PointerField[T]) AppendValidators(validators []Validator)
- func (f *PointerField[T]) Assign(data map[string]interface{}, schema *Schema) error
- func (f *PointerField[T]) Description() string
- func (f *PointerField[T]) Name() string
- func (f *PointerField[T]) SetCallback(callback func(*Schema, *T))
- func (f *PointerField[T]) SetDefaultValue(defaultValue T)
- func (f *PointerField[T]) SetDescription(description string)
- func (f *PointerField[T]) Validate(schema *Schema) error
- func (f *PointerField[T]) Value() interface{}
- type RequiredValidator
- type Schema
- func (s *Schema) Apply(data map[string]interface{}, options ...SchemaOption) error
- func (s *Schema) ApplyHTTPRequest(w http.ResponseWriter, r *http.Request, httpRequestOption *HTTPRequestOption, ...) error
- func (s *Schema) ApplyJSON(jsonData []byte, options ...SchemaOption) error
- func (s *Schema) GetFieldValue(fieldName string) (interface{}, bool)
- func (s *Schema) IsFieldPresent(fieldName string) bool
- func (s *Schema) SetFieldPresent(fieldName string)
- type SchemaOption
- type SliceField
- func (f *SliceField[T]) AddTransformer(transformer Transformer[[]T])
- func (f *SliceField[T]) AppendValidators(validators []Validator)
- func (f *SliceField[T]) Assign(data map[string]interface{}, schema *Schema) error
- func (f *SliceField[T]) Description() string
- func (f *SliceField[T]) Name() string
- func (f *SliceField[T]) SetCallback(callback func(*Schema, *T))
- func (f *SliceField[T]) SetDefaultValue(defaultValue []T)
- func (f *SliceField[T]) SetDescription(description string)
- func (f *SliceField[T]) Validate(schema *Schema) error
- func (f *SliceField[T]) Value() interface{}
- type StructField
- func (f *StructField[T]) AppendValidators(validators []Validator)
- func (f *StructField[T]) Assign(data map[string]interface{}, schema *Schema) error
- func (f *StructField[T]) Description() string
- func (f *StructField[T]) Name() string
- func (f *StructField[T]) SetCallback(callback func(*Schema, *T))
- func (f *StructField[T]) SetDefaultValue(defaultValue T)
- func (f *StructField[T]) SetDescription(description string)
- func (f *StructField[T]) Validate(schema *Schema) error
- func (f *StructField[T]) Value() interface{}
- type SubSchemaInterface
- type SubSchemaMapInterface
- type SubSchemaMapOption
- type SubSchemaOption
- type Transformer
- type TransformerFn
- type TransformerOption
- type UnionField
- func (f *UnionField) Assign(data map[string]interface{}, schema *Schema) error
- func (f *UnionField) Description() string
- func (f *UnionField) Name() string
- func (f *UnionField) SetDescription(description string)
- func (f *UnionField) Validate(schema *Schema) error
- func (f *UnionField) Value() interface{}
- type Validator
- func Each(validators ...Validator) Validator
- func Email() Validator
- func In(values ...interface{}) Validator
- func Max(max interface{}) Validator
- func MaxLength(maxLen int) Validator
- func Min(min interface{}) Validator
- func MinLength(minLen int) Validator
- func NewInterfaceValidator(fn func(interface{}, string) error) Validator
- func NotEmpty() Validator
- func Required() Validator
- func URL() Validator
- func Unique() Validator
- func UniqueBy(keyExtractor func(interface{}) interface{}) Validator
- func ValidatorFunc[T any](fn func(value T, fieldName string) error) Validator
- func WithMapKeys(keys ...string) Validator
- type ValidatorFn
- type ValidatorsAppender
- type ValidatorsOption
- type ValueField
- func (f *ValueField[T]) AddTransformer(transformer Transformer[T])
- func (f *ValueField[T]) AppendValidators(validators []Validator)
- func (f *ValueField[T]) Assign(data map[string]interface{}, schema *Schema) error
- func (f *ValueField[T]) Description() string
- func (f *ValueField[T]) Name() string
- func (f *ValueField[T]) SetDefaultValue(defaultValue T)
- func (f *ValueField[T]) SetDescription(description string)
- func (f *ValueField[T]) Validate(schema *Schema) error
- func (f *ValueField[T]) Value() interface{}
- type ValueWithoutAssignField
- func (f *ValueWithoutAssignField[T]) AppendValidators(validators []Validator)
- func (f *ValueWithoutAssignField[T]) Assign(data map[string]interface{}, schema *Schema) error
- func (f *ValueWithoutAssignField[T]) Description() string
- func (f *ValueWithoutAssignField[T]) Name() string
- func (f *ValueWithoutAssignField[T]) SetDescription(description string)
- func (f *ValueWithoutAssignField[T]) Validate(schema *Schema) error
- func (f *ValueWithoutAssignField[T]) Value() interface{}
Constants ¶
This section is empty.
Variables ¶
var MaxBodySize int64 = 5 << 20 // 5MB limit
MaxBodySize is the maximum size of the body of an HTTP request You can change this value to limit the size of the body of an HTTP request
Functions ¶
Types ¶
type ArrayField ¶
ArrayField represents an array field
func (*ArrayField[T]) AddTransformer ¶
func (f *ArrayField[T]) AddTransformer(transformer Transformer[interface{}])
AddTransformer adds a transformer to the field
func (*ArrayField[T]) AppendValidators ¶
func (f *ArrayField[T]) AppendValidators(validators []Validator)
AppendValidators implements ValidatorsAppender interface
func (*ArrayField[T]) Assign ¶
func (f *ArrayField[T]) Assign(data map[string]interface{}, schema *Schema) error
Assign assigns a value to the field from the input data
func (*ArrayField[T]) Description ¶
func (f *ArrayField[T]) Description() string
Description returns the field description
func (*ArrayField[T]) SetDefaultValue ¶
func (f *ArrayField[T]) SetDefaultValue(defaultValue interface{})
SetDefaultValue sets the default value for the field
func (*ArrayField[T]) SetDescription ¶
func (f *ArrayField[T]) SetDescription(description string)
SetDescription sets the field description
func (*ArrayField[T]) Validate ¶
func (f *ArrayField[T]) Validate(schema *Schema) error
Validate validates the field value using all registered validators
func (*ArrayField[T]) Value ¶
func (f *ArrayField[T]) Value() interface{}
Value returns the current value of the field
type ContentTypeParsing ¶
type ContentTypeParsing uint8
const ( ContentTypeParsingAuto ContentTypeParsing = iota ContentTypeParsingJSON ContentTypeParsingForm ContentTypeParsingQuery )
type ConvertField ¶
type ConvertField[From, To any] struct { Validators []Validator // contains filtered or unexported fields }
ConvertField represents a field with type conversion
func (*ConvertField[From, To]) AddTransformer ¶
func (f *ConvertField[From, To]) AddTransformer(transformer Transformer[To])
AddTransformer adds a transformer to the field
func (*ConvertField[From, To]) AppendValidators ¶
func (f *ConvertField[From, To]) AppendValidators(validators []Validator)
AppendValidators implements ValidatorsAppender interface
func (*ConvertField[From, To]) Assign ¶
func (f *ConvertField[From, To]) Assign(data map[string]interface{}, schema *Schema) error
Assign assigns a value to the field from the input data
func (*ConvertField[From, To]) Description ¶
func (f *ConvertField[From, To]) Description() string
Description returns the field description
func (*ConvertField[From, To]) Name ¶
func (f *ConvertField[From, To]) Name() string
Name returns the field name
func (*ConvertField[From, To]) SetDefaultValue ¶
func (f *ConvertField[From, To]) SetDefaultValue(defaultValue To)
SetDefaultValue sets the default value for the field
func (*ConvertField[From, To]) SetDescription ¶
func (f *ConvertField[From, To]) SetDescription(description string)
SetDescription sets the field description
func (*ConvertField[From, To]) Validate ¶
func (f *ConvertField[From, To]) Validate(schema *Schema) error
Validate validates the field value using all registered validators
func (*ConvertField[From, To]) Value ¶
func (f *ConvertField[From, To]) Value() interface{}
Value returns the current value of the field
type ConvertPointerField ¶
type ConvertPointerField[From, To any] struct { Validators []Validator // contains filtered or unexported fields }
ConvertPointerField represents a field with type conversion to pointer
func (*ConvertPointerField[From, To]) AddTransformer ¶
func (f *ConvertPointerField[From, To]) AddTransformer(transformer Transformer[To])
AddTransformer adds a transformer to the field
func (*ConvertPointerField[From, To]) AppendValidators ¶
func (f *ConvertPointerField[From, To]) AppendValidators(validators []Validator)
AppendValidators implements ValidatorsAppender interface
func (*ConvertPointerField[From, To]) Assign ¶
func (f *ConvertPointerField[From, To]) Assign(data map[string]interface{}, schema *Schema) error
Assign assigns a value to the field from the input data
func (*ConvertPointerField[From, To]) Description ¶
func (f *ConvertPointerField[From, To]) Description() string
Description returns the field description
func (*ConvertPointerField[From, To]) Name ¶
func (f *ConvertPointerField[From, To]) Name() string
Name returns the field name
func (*ConvertPointerField[From, To]) SetDefaultValue ¶
func (f *ConvertPointerField[From, To]) SetDefaultValue(defaultValue To)
SetDefaultValue sets the default value for the field
func (*ConvertPointerField[From, To]) SetDescription ¶
func (f *ConvertPointerField[From, To]) SetDescription(description string)
SetDescription sets the field description
func (*ConvertPointerField[From, To]) Validate ¶
func (f *ConvertPointerField[From, To]) Validate(schema *Schema) error
Validate validates the field value using all registered validators
func (*ConvertPointerField[From, To]) Value ¶
func (f *ConvertPointerField[From, To]) Value() interface{}
Value returns the current value of the field
type DefaultOption ¶
type DefaultOption[T any] struct { // contains filtered or unexported fields }
DefaultOption holds a default value
func (DefaultOption[T]) Apply ¶
func (o DefaultOption[T]) Apply(field interface{})
Apply applies the default value to the field
type DefaultValueSetter ¶
type DefaultValueSetter[T any] interface { SetDefaultValue(defaultValue T) }
DefaultValueSetter is an interface for fields that can set default values
type DescriptionOption ¶
type DescriptionOption struct {
// contains filtered or unexported fields
}
DescriptionOption holds a description
func (DescriptionOption) Apply ¶
func (o DescriptionOption) Apply(field interface{})
Apply applies the description to the field
type Field ¶
type Field interface {
// Name returns the name of the field
Name() string
// Value returns the current value of the field
Value() interface{}
// Description returns the description of the field
Description() string
// SetDescription sets the description of the field
SetDescription(description string)
// Assign assigns a value to the field from the input data
Assign(data map[string]interface{}, schema *Schema) error
// Validate validates the field value using all registered validators
Validate(schema *Schema) error
}
Field represents a field definition in a schema
func Convert ¶
func Convert[From, To any](name string, ptr *To, convert func(From) (*To, error), opts ...Option) Field
Convert creates a conversion field
func ConvertPointer ¶
func ConvertPointer[From, To any](name string, ptr **To, convert func(From) (*To, error), opts ...Option) Field
ConvertPointer creates a conversion field for pointer types
func HTTPMap ¶
func HTTPMap[K comparable, V any](name string, ptr *map[K]V, opts ...Option) Field
HTTPMap creates an HTTP map field
func Map ¶
func Map[K comparable, V any](name string, ptr *map[K]V, opts ...Option) Field
Map creates a map field
func NestedMap ¶
func NestedMap[K comparable, V any](name string, ptr *map[K]V, opts ...Option) Field
NestedMap creates a nested map field
func Union ¶
func Union(name string, ptr interface{}, resolver func(map[string]interface{}) (interface{}, error)) Field
Union creates a union field
type FieldError ¶
FieldError represents a validation error for a specific field
type HTTPMapCallbackOption ¶
type HTTPMapCallbackOption[K comparable, V any] struct { // contains filtered or unexported fields }
HTTPMapCallbackOption holds a callback function for HTTPMap
func (HTTPMapCallbackOption[K, V]) Apply ¶
func (o HTTPMapCallbackOption[K, V]) Apply(field interface{})
Apply applies the callback to the HTTPMap field
type HTTPMapField ¶
type HTTPMapField[K comparable, V any] struct { Validators []Validator // contains filtered or unexported fields }
HTTPMapField represents a map field where each value is a struct
func (*HTTPMapField[K, V]) AppendValidators ¶
func (f *HTTPMapField[K, V]) AppendValidators(validators []Validator)
AppendValidators implements ValidatorsAppender interface
func (*HTTPMapField[K, V]) Assign ¶
func (f *HTTPMapField[K, V]) Assign(data map[string]interface{}, schema *Schema) error
Assign assigns a value to the field from the input data
func (*HTTPMapField[K, V]) Description ¶
func (f *HTTPMapField[K, V]) Description() string
Description returns the field description
func (*HTTPMapField[K, V]) Name ¶
func (f *HTTPMapField[K, V]) Name() string
Name returns the field name
func (*HTTPMapField[K, V]) SetCallback ¶
func (f *HTTPMapField[K, V]) SetCallback(callback func(*Schema, *V))
SetCallback sets the callback function for configuring sub-schemas
func (*HTTPMapField[K, V]) SetDefaultValue ¶
func (f *HTTPMapField[K, V]) SetDefaultValue(defaultValue map[K]V)
SetDefaultValue sets the default value for the field
func (*HTTPMapField[K, V]) SetDescription ¶
func (f *HTTPMapField[K, V]) SetDescription(description string)
SetDescription sets the field description
func (*HTTPMapField[K, V]) Validate ¶
func (f *HTTPMapField[K, V]) Validate(schema *Schema) error
Validate validates the field value using all registered validators
func (*HTTPMapField[K, V]) Value ¶
func (f *HTTPMapField[K, V]) Value() interface{}
Value returns the current value of the field
type HTTPRequestOption ¶
type HTTPRequestOption struct {
MaxRequestBodySize int64
ContentTypeParsing ContentTypeParsing
}
type MapField ¶
type MapField[K comparable, V any] struct { Validators []Validator // contains filtered or unexported fields }
MapField represents a map field
func (*MapField[K, V]) AppendValidators ¶
AppendValidators implements ValidatorsAppender interface
func (*MapField[K, V]) Description ¶
Description returns the field description
func (*MapField[K, V]) SetCallback ¶
SetCallback sets the callback function for configuring sub-schemas
func (*MapField[K, V]) SetDefaultValue ¶
func (f *MapField[K, V]) SetDefaultValue(defaultValue map[K]V)
SetDefaultValue sets the default value for the field
func (*MapField[K, V]) SetDescription ¶
SetDescription sets the field description
type NestedMapField ¶
type NestedMapField[K comparable, V any] struct { Validators []Validator // contains filtered or unexported fields }
NestedMapField represents a nested map field
func (*NestedMapField[K, V]) AppendValidators ¶
func (f *NestedMapField[K, V]) AppendValidators(validators []Validator)
AppendValidators implements ValidatorsAppender interface
func (*NestedMapField[K, V]) Assign ¶
func (f *NestedMapField[K, V]) Assign(data map[string]interface{}, schema *Schema) error
Assign assigns a value to the field from the input data
func (*NestedMapField[K, V]) Description ¶
func (f *NestedMapField[K, V]) Description() string
Description returns the field description
func (*NestedMapField[K, V]) Name ¶
func (f *NestedMapField[K, V]) Name() string
Name returns the field name
func (*NestedMapField[K, V]) SetCallback ¶
func (f *NestedMapField[K, V]) SetCallback(callback func(*Schema, K, V))
SetCallback implements SubSchemaMapInterface
func (*NestedMapField[K, V]) SetDefaultValue ¶
func (f *NestedMapField[K, V]) SetDefaultValue(defaultValue map[K]V)
SetDefaultValue sets the default value for the field
func (*NestedMapField[K, V]) SetDescription ¶
func (f *NestedMapField[K, V]) SetDescription(description string)
SetDescription sets the field description
func (*NestedMapField[K, V]) Validate ¶
func (f *NestedMapField[K, V]) Validate(schema *Schema) error
Validate validates the field value using all registered validators
func (*NestedMapField[K, V]) Value ¶
func (f *NestedMapField[K, V]) Value() interface{}
Value returns the current value of the field
type Option ¶
type Option interface {
Apply(interface{})
}
Option represents a configuration option
func WithDefault ¶
WithDefault creates a default value option
func WithDescription ¶
WithDescription creates a description option
func WithHTTPMapCallback ¶
func WithHTTPMapCallback[K comparable, V any](callback func(*Schema, *V)) Option
WithHTTPMapCallback creates a callback option for HTTPMap
func WithSubSchema ¶
WithSubSchema creates a sub-schema option
func WithSubSchemaMap ¶
func WithSubSchemaMap[K comparable, V any](callback func(*Schema, K, V)) Option
WithSubSchemaMap creates a map sub-schema option
func WithTransformers ¶
func WithTransformers[T any](transformers ...Transformer[T]) Option
WithTransformers creates a transformers option
func WithValidators ¶
WithValidators creates a validators option
type PointerField ¶
type PointerField[T any] struct { Validators []Validator // contains filtered or unexported fields }
PointerField represents a pointer field
func (*PointerField[T]) AddTransformer ¶
func (f *PointerField[T]) AddTransformer(transformer Transformer[T])
AddTransformer adds a transformer to the field
func (*PointerField[T]) AppendValidators ¶
func (f *PointerField[T]) AppendValidators(validators []Validator)
AppendValidators implements ValidatorsAppender interface
func (*PointerField[T]) Assign ¶
func (f *PointerField[T]) Assign(data map[string]interface{}, schema *Schema) error
Assign assigns a value to the field from the input data
func (*PointerField[T]) Description ¶
func (f *PointerField[T]) Description() string
Description returns the field description
func (*PointerField[T]) SetCallback ¶
func (f *PointerField[T]) SetCallback(callback func(*Schema, *T))
SetCallback sets the callback function for configuring sub-schemas
func (*PointerField[T]) SetDefaultValue ¶
func (f *PointerField[T]) SetDefaultValue(defaultValue T)
SetDefaultValue sets the default value for the field
func (*PointerField[T]) SetDescription ¶
func (f *PointerField[T]) SetDescription(description string)
SetDescription sets the field description
func (*PointerField[T]) Validate ¶
func (f *PointerField[T]) Validate(schema *Schema) error
Validate validates the field value using all registered validators
func (*PointerField[T]) Value ¶
func (f *PointerField[T]) Value() interface{}
Value returns the current value of the field
type RequiredValidator ¶
type RequiredValidator struct {
// contains filtered or unexported fields
}
RequiredValidator is a special validator that needs access to the schema
func (RequiredValidator) Validate ¶
func (v RequiredValidator) Validate(value interface{}, fieldName string) error
Validate validates that the field is present and not empty
func (RequiredValidator) ValidateWithSchema ¶
func (v RequiredValidator) ValidateWithSchema(schema *Schema, fieldName string) error
ValidateWithSchema validates field presence using schema context
func (RequiredValidator) WithMessage ¶
func (v RequiredValidator) WithMessage(msg string) Validator
WithMessage sets a custom error message for the validator
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema represents a validation schema
func (*Schema) Apply ¶
func (s *Schema) Apply(data map[string]interface{}, options ...SchemaOption) error
Apply assigns data to variables and validates them
func (*Schema) ApplyHTTPRequest ¶
func (s *Schema) ApplyHTTPRequest(w http.ResponseWriter, r *http.Request, httpRequestOption *HTTPRequestOption, options ...SchemaOption) error
ApplyHTTPRequest assigns data from an HTTP request to a schema It supports application/json and application/x-www-form-urlencoded It will return an error if the content type is not supported
func (*Schema) ApplyJSON ¶
func (s *Schema) ApplyJSON(jsonData []byte, options ...SchemaOption) error
ApplyJSON assigns data from a JSON string to a schema
func (*Schema) GetFieldValue ¶
GetFieldValue returns the value of a field by name
func (*Schema) IsFieldPresent ¶
IsFieldPresent checks if a field was present in the input data
func (*Schema) SetFieldPresent ¶
SetFieldPresent marks a field as present in the input data
type SchemaOption ¶
type SchemaOption func(*Schema)
SchemaOption represents a configuration option for a schema
func WithSkipValidators ¶
func WithSkipValidators(skipValidators bool) SchemaOption
WithSkipValidators creates a schema option to skip validation
type SliceField ¶
SliceField represents a slice field where each element is a struct
func (*SliceField[T]) AddTransformer ¶
func (f *SliceField[T]) AddTransformer(transformer Transformer[[]T])
AddTransformer adds a transformer to the field
func (*SliceField[T]) AppendValidators ¶
func (f *SliceField[T]) AppendValidators(validators []Validator)
AppendValidators implements ValidatorsAppender interface
func (*SliceField[T]) Assign ¶
func (f *SliceField[T]) Assign(data map[string]interface{}, schema *Schema) error
Assign assigns a value to the field from the input data
func (*SliceField[T]) Description ¶
func (f *SliceField[T]) Description() string
Description returns the field description
func (*SliceField[T]) SetCallback ¶
func (f *SliceField[T]) SetCallback(callback func(*Schema, *T))
SetCallback sets the callback function for configuring sub-schemas
func (*SliceField[T]) SetDefaultValue ¶
func (f *SliceField[T]) SetDefaultValue(defaultValue []T)
SetDefaultValue sets the default value for the field
func (*SliceField[T]) SetDescription ¶
func (f *SliceField[T]) SetDescription(description string)
SetDescription sets the field description
func (*SliceField[T]) Validate ¶
func (f *SliceField[T]) Validate(schema *Schema) error
Validate validates the field value using all registered validators
func (*SliceField[T]) Value ¶
func (f *SliceField[T]) Value() interface{}
Value returns the current value of the field
type StructField ¶
StructField represents a struct field with callback
func (*StructField[T]) AppendValidators ¶
func (f *StructField[T]) AppendValidators(validators []Validator)
AppendValidators implements ValidatorsAppender interface
func (*StructField[T]) Assign ¶
func (f *StructField[T]) Assign(data map[string]interface{}, schema *Schema) error
Assign assigns a value to the field from the input data
func (*StructField[T]) Description ¶
func (f *StructField[T]) Description() string
Description returns the field description
func (*StructField[T]) SetCallback ¶
func (f *StructField[T]) SetCallback(callback func(*Schema, *T))
SetCallback sets the callback function for configuring sub-schemas
func (*StructField[T]) SetDefaultValue ¶
func (f *StructField[T]) SetDefaultValue(defaultValue T)
SetDefaultValue sets the default value for the field
func (*StructField[T]) SetDescription ¶
func (f *StructField[T]) SetDescription(description string)
SetDescription sets the field description
func (*StructField[T]) Validate ¶
func (f *StructField[T]) Validate(schema *Schema) error
Validate validates the field value using all registered validators
func (*StructField[T]) Value ¶
func (f *StructField[T]) Value() interface{}
Value returns the current value of the field
type SubSchemaInterface ¶
SubSchemaInterface is an interface for fields that can set sub-schema callbacks
type SubSchemaMapInterface ¶
type SubSchemaMapInterface[K comparable, V any] interface { SetCallback(func(*Schema, K, V)) }
SubSchemaMapInterface is an interface for map fields that can set sub-schema callbacks
type SubSchemaMapOption ¶
type SubSchemaMapOption[K comparable, V any] struct { // contains filtered or unexported fields }
SubSchemaMapOption holds a callback for configuring map sub-schemas
func (SubSchemaMapOption[K, V]) Apply ¶
func (o SubSchemaMapOption[K, V]) Apply(field interface{})
Apply applies the map sub-schema callback to the field
type SubSchemaOption ¶
type SubSchemaOption[T any] struct { // contains filtered or unexported fields }
SubSchemaOption holds a callback for configuring sub-schemas
func (SubSchemaOption[T]) Apply ¶
func (o SubSchemaOption[T]) Apply(field interface{})
Apply applies the sub-schema callback to the field
type Transformer ¶
type Transformer[T any] interface { // Transform applies the transformation to the given value Transform(value T) (T, error) }
Transformer represents a function that transforms a value before assignment and validation
func Capitalize ¶
func Capitalize() Transformer[string]
Capitalize transforms a string to capitalize first letter
func CustomTransformer ¶
func CustomTransformer[T any](transform func(T) (T, error)) Transformer[T]
CustomTransformer creates a custom transformer from a function
func SanitizeEmail ¶
func SanitizeEmail() Transformer[string]
SanitizeEmail normalizes email addresses
func TrimSpace ¶
func TrimSpace() Transformer[string]
TrimSpace removes leading and trailing whitespace
type TransformerFn ¶
type TransformerFn[T any] struct { // contains filtered or unexported fields }
TransformerFn is a function that implements Transformer
func (TransformerFn[T]) Transform ¶
func (t TransformerFn[T]) Transform(value T) (T, error)
Transform applies the transformation function to the value
type TransformerOption ¶
type TransformerOption[T any] struct { // contains filtered or unexported fields }
TransformerOption holds transformers
func (TransformerOption[T]) Apply ¶
func (o TransformerOption[T]) Apply(field interface{})
Apply applies the transformers to the field
type UnionField ¶
type UnionField struct {
// contains filtered or unexported fields
}
UnionField represents a union/polymorphic field
func (*UnionField) Assign ¶
func (f *UnionField) Assign(data map[string]interface{}, schema *Schema) error
Assign assigns a value to the field from the input data
func (*UnionField) Description ¶
func (f *UnionField) Description() string
Description returns the field description
func (*UnionField) SetDescription ¶
func (f *UnionField) SetDescription(description string)
SetDescription sets the field description
func (*UnionField) Validate ¶
func (f *UnionField) Validate(schema *Schema) error
Validate validates the field value using all registered validators
func (*UnionField) Value ¶
func (f *UnionField) Value() interface{}
Value returns the current value of the field
type Validator ¶
type Validator interface {
// Validate validates a value and returns an error if validation fails
Validate(value interface{}, fieldName string) error
// WithMessage sets a custom error message for the validator
WithMessage(msg string) Validator
}
Validator represents a validation function
func In ¶
func In(values ...interface{}) Validator
In validator validates that a value is one of the specified values
func Max ¶
func Max(max interface{}) Validator
Max validator validates that a numeric value is at most the specified maximum
func MaxLength ¶
MaxLength validator validates that a string or slice has at most the specified length
func Min ¶
func Min(min interface{}) Validator
Min validator validates that a numeric value is at least the specified minimum
func MinLength ¶
MinLength validator validates that a string or slice has at least the specified length
func NewInterfaceValidator ¶
NewInterfaceValidator creates a validator that can handle interface{} values This is used for backward compatibility with existing validators
func NotEmpty ¶
func NotEmpty() Validator
NotEmpty validator - rejects zero values (use this for non-zero value requirements)
func Required ¶
func Required() Validator
Required validator - checks if field was present in input data, not if value is non-zero
func Unique ¶
func Unique() Validator
Unique validator ensures all elements in slices, arrays, or maps are unique
func UniqueBy ¶
func UniqueBy(keyExtractor func(interface{}) interface{}) Validator
UniqueBy validator ensures all elements in slices/arrays are unique by a specific key extractor function
func ValidatorFunc ¶
ValidatorFunc creates a custom validator from a function (simplified version)
func WithMapKeys ¶
WithMapKeys validator ensures that a map contains all the specified keys
type ValidatorFn ¶
type ValidatorFn[T any] struct { // contains filtered or unexported fields }
ValidatorFn is a generic function that implements Validator
func NewValidatorFn ¶
func NewValidatorFn[T any](fn func(T, string) error) ValidatorFn[T]
NewValidatorFn creates a new ValidatorFn with type safety
func (ValidatorFn[T]) Validate ¶
func (v ValidatorFn[T]) Validate(value interface{}, fieldName string) error
Validate validates a value using the validator function
func (ValidatorFn[T]) WithMessage ¶
func (v ValidatorFn[T]) WithMessage(msg string) Validator
WithMessage sets a custom error message for the validator
type ValidatorsAppender ¶
type ValidatorsAppender interface {
AppendValidators(validators []Validator)
}
ValidatorsAppender is an interface for fields that can append validators
type ValidatorsOption ¶
type ValidatorsOption struct {
// contains filtered or unexported fields
}
ValidatorsOption holds validators
func (ValidatorsOption) Apply ¶
func (o ValidatorsOption) Apply(field interface{})
Apply applies the validators to the field
type ValueField ¶
ValueField represents a basic value field
func (*ValueField[T]) AddTransformer ¶
func (f *ValueField[T]) AddTransformer(transformer Transformer[T])
AddTransformer adds a transformer to the field
func (*ValueField[T]) AppendValidators ¶
func (f *ValueField[T]) AppendValidators(validators []Validator)
AppendValidators implements ValidatorsAppender interface
func (*ValueField[T]) Assign ¶
func (f *ValueField[T]) Assign(data map[string]interface{}, schema *Schema) error
Assign assigns a value to the field from the input data
func (*ValueField[T]) Description ¶
func (f *ValueField[T]) Description() string
Description returns the field description
func (*ValueField[T]) SetDefaultValue ¶
func (f *ValueField[T]) SetDefaultValue(defaultValue T)
SetDefaultValue sets the default value for the field
func (*ValueField[T]) SetDescription ¶
func (f *ValueField[T]) SetDescription(description string)
SetDescription sets the field description
func (*ValueField[T]) Validate ¶
func (f *ValueField[T]) Validate(schema *Schema) error
Validate validates the field value using all registered validators
func (*ValueField[T]) Value ¶
func (f *ValueField[T]) Value() interface{}
Value returns the current value of the field
type ValueWithoutAssignField ¶
type ValueWithoutAssignField[T any] struct { Validators []Validator // contains filtered or unexported fields }
ValueWithoutAssignField represents a field that validates a direct value
func (*ValueWithoutAssignField[T]) AppendValidators ¶
func (f *ValueWithoutAssignField[T]) AppendValidators(validators []Validator)
AppendValidators implements ValidatorsAppender interface
func (*ValueWithoutAssignField[T]) Assign ¶
func (f *ValueWithoutAssignField[T]) Assign(data map[string]interface{}, schema *Schema) error
Assign assigns a value to the field from the input data
func (*ValueWithoutAssignField[T]) Description ¶
func (f *ValueWithoutAssignField[T]) Description() string
Description returns the field description
func (*ValueWithoutAssignField[T]) Name ¶
func (f *ValueWithoutAssignField[T]) Name() string
Name returns the field name
func (*ValueWithoutAssignField[T]) SetDescription ¶
func (f *ValueWithoutAssignField[T]) SetDescription(description string)
SetDescription sets the field description
func (*ValueWithoutAssignField[T]) Validate ¶
func (f *ValueWithoutAssignField[T]) Validate(schema *Schema) error
Validate validates the field value using all registered validators
func (*ValueWithoutAssignField[T]) Value ¶
func (f *ValueWithoutAssignField[T]) Value() interface{}
Value returns the current value of the field
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
advanced_features
command
|
|
|
basic
command
|
|
|
date_conversion
command
|
|
|
debug
command
|
|
|
dsl_v2
command
|
|
|
http_advanced
command
|
|
|
http_basic
command
|
|
|
require
command
|
|
|
transformers
command
|