Documentation
¶
Overview ¶
datetime.go - Date/Time validation builder for Queryfy
dependent.go - Dependent fields validation for Queryfy
transform.go - Transformation support for Queryfy
Index ¶
- type AndSchema
- type ArraySchema
- func (s *ArraySchema) Custom(fn queryfy.ValidatorFunc) *ArraySchema
- func (s *ArraySchema) Length(length int) *ArraySchema
- func (s *ArraySchema) MaxItems(max int) *ArraySchema
- func (s *ArraySchema) MinItems(min int) *ArraySchema
- func (s *ArraySchema) Nullable() *ArraySchema
- func (s *ArraySchema) Of(schema queryfy.Schema) *ArraySchema
- func (s *ArraySchema) Optional() *ArraySchema
- func (s *ArraySchema) Required() *ArraySchema
- func (s *ArraySchema) Transform(transformer Transformer) *TransformSchema
- func (s *ArraySchema) Type() queryfy.SchemaType
- func (s *ArraySchema) UniqueItems() *ArraySchema
- func (s *ArraySchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- type BoolSchema
- func (s *BoolSchema) Custom(fn queryfy.ValidatorFunc) *BoolSchema
- func (s *BoolSchema) Nullable() *BoolSchema
- func (s *BoolSchema) Optional() *BoolSchema
- func (s *BoolSchema) Required() *BoolSchema
- func (s *BoolSchema) Transform(transformer Transformer) *TransformSchema
- func (s *BoolSchema) Type() queryfy.SchemaType
- func (s *BoolSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- type CustomSchema
- type DateTimeSchema
- func (s *DateTimeSchema) Age(minAge, maxAge int) *DateTimeSchema
- func (s *DateTimeSchema) Between(min, max time.Time) *DateTimeSchema
- func (s *DateTimeSchema) BetweenStrings(min, max string) *DateTimeSchema
- func (s *DateTimeSchema) BusinessDay() *DateTimeSchema
- func (s *DateTimeSchema) Custom(fn queryfy.ValidatorFunc) *DateTimeSchema
- func (s *DateTimeSchema) DMY() *DateTimeSchema
- func (s *DateTimeSchema) DateOnly() *DateTimeSchema
- func (s *DateTimeSchema) Format(format string) *DateTimeSchema
- func (s *DateTimeSchema) Future() *DateTimeSchema
- func (s *DateTimeSchema) ISO8601() *DateTimeSchema
- func (s *DateTimeSchema) MDY() *DateTimeSchema
- func (s *DateTimeSchema) Max(max time.Time) *DateTimeSchema
- func (s *DateTimeSchema) MaxString(max string) *DateTimeSchema
- func (s *DateTimeSchema) Min(min time.Time) *DateTimeSchema
- func (s *DateTimeSchema) MinString(min string) *DateTimeSchema
- func (s *DateTimeSchema) Nullable() *DateTimeSchema
- func (s *DateTimeSchema) Optional() *DateTimeSchema
- func (s *DateTimeSchema) Past() *DateTimeSchema
- func (s *DateTimeSchema) Required() *DateTimeSchema
- func (s *DateTimeSchema) Transform(transformer Transformer) *TransformSchema
- func (s *DateTimeSchema) Type() queryfy.SchemaType
- func (s *DateTimeSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- func (s *DateTimeSchema) Weekday(days ...time.Weekday) *DateTimeSchema
- func (s *DateTimeSchema) YMD() *DateTimeSchema
- type DependencyCondition
- func WhenAll(conditions ...DependencyCondition) DependencyCondition
- func WhenAny(conditions ...DependencyCondition) DependencyCondition
- func WhenEquals(field string, value interface{}) DependencyCondition
- func WhenExists(field string) DependencyCondition
- func WhenFalse(field string) DependencyCondition
- func WhenGreaterThan(field string, threshold float64) DependencyCondition
- func WhenIn(field string, values ...interface{}) DependencyCondition
- func WhenLessThan(field string, threshold float64) DependencyCondition
- func WhenNotEquals(field string, value interface{}) DependencyCondition
- func WhenNotExists(field string) DependencyCondition
- func WhenTrue(field string) DependencyCondition
- type DependentSchema
- func (s *DependentSchema) Custom(fn queryfy.ValidatorFunc) *DependentSchema
- func (s *DependentSchema) Else(elseSchema queryfy.Schema) *DependentSchema
- func (s *DependentSchema) On(fields ...string) *DependentSchema
- func (s *DependentSchema) Optional() *DependentSchema
- func (s *DependentSchema) Required() *DependentSchema
- func (s *DependentSchema) Then(schema queryfy.Schema) *DependentSchema
- func (s *DependentSchema) Type() queryfy.SchemaType
- func (s *DependentSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- func (s *DependentSchema) ValidateWithParent(value interface{}, parentData map[string]interface{}, ...) error
- func (s *DependentSchema) When(condition DependencyCondition) *DependentSchema
- type NotSchema
- type NumberSchema
- func (s *NumberSchema) Custom(fn queryfy.ValidatorFunc) *NumberSchema
- func (s *NumberSchema) Integer() *NumberSchema
- func (s *NumberSchema) Max(max float64) *NumberSchema
- func (s *NumberSchema) Min(min float64) *NumberSchema
- func (s *NumberSchema) MultipleOf(value float64) *NumberSchema
- func (s *NumberSchema) Negative() *NumberSchema
- func (s *NumberSchema) Nullable() *NumberSchema
- func (s *NumberSchema) Optional() *NumberSchema
- func (s *NumberSchema) Positive() *NumberSchema
- func (s *NumberSchema) Range(min, max float64) *NumberSchema
- func (s *NumberSchema) Required() *NumberSchema
- func (s *NumberSchema) Transform(transformer Transformer) *TransformSchema
- func (s *NumberSchema) Type() queryfy.SchemaType
- func (s *NumberSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- type ObjectSchema
- func (s *ObjectSchema) Custom(fn queryfy.ValidatorFunc) *ObjectSchema
- func (s *ObjectSchema) Field(name string, schema queryfy.Schema) *ObjectSchema
- func (s *ObjectSchema) FieldNames() []string
- func (s *ObjectSchema) Fields(fields map[string]queryfy.Schema) *ObjectSchema
- func (s *ObjectSchema) Nullable() *ObjectSchema
- func (s *ObjectSchema) Optional() *ObjectSchema
- func (s *ObjectSchema) Required() *ObjectSchema
- func (s *ObjectSchema) RequiredFields(names ...string) *ObjectSchema
- func (s *ObjectSchema) String() string
- func (s *ObjectSchema) Transform(transformer Transformer) *TransformSchema
- func (s *ObjectSchema) Type() queryfy.SchemaType
- func (s *ObjectSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- func (s *ObjectSchema) WithDependencies() *ObjectSchemaWithDependencies
- type ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) Custom(fn queryfy.ValidatorFunc) *ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) DependentField(name string, dependent *DependentSchema) *ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) Field(name string, schema queryfy.Schema) *ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) Fields(fields map[string]queryfy.Schema) *ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) Nullable() *ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) Optional() *ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) Required() *ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) RequiredFields(names ...string) *ObjectSchemaWithDependencies
- func (s *ObjectSchemaWithDependencies) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- type OrSchema
- type StringSchema
- func (s *StringSchema) Custom(fn queryfy.ValidatorFunc) *StringSchema
- func (s *StringSchema) Email() *StringSchema
- func (s *StringSchema) Enum(values ...string) *StringSchema
- func (s *StringSchema) Length(length int) *StringSchema
- func (s *StringSchema) MaxLength(max int) *StringSchema
- func (s *StringSchema) MinLength(min int) *StringSchema
- func (s *StringSchema) Nullable() *StringSchema
- func (s *StringSchema) Optional() *StringSchema
- func (s *StringSchema) Pattern(pattern string) *StringSchema
- func (s *StringSchema) Required() *StringSchema
- func (s *StringSchema) Transform(transformer Transformer) *TransformSchema
- func (s *StringSchema) Type() queryfy.SchemaType
- func (s *StringSchema) URL() *StringSchema
- func (s *StringSchema) UUID() *StringSchema
- func (s *StringSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- type TransformSchema
- func (s *TransformSchema) Add(transformer Transformer) *TransformSchema
- func (s *TransformSchema) Optional() *TransformSchema
- func (s *TransformSchema) Required() *TransformSchema
- func (s *TransformSchema) Type() queryfy.SchemaType
- func (s *TransformSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
- func (s *TransformSchema) ValidateAndTransform(value interface{}, ctx *queryfy.ValidationContext) (interface{}, error)
- type Transformer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AndSchema ¶
type AndSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
AndSchema validates that all schemas pass.
func (*AndSchema) Type ¶
func (s *AndSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
type ArraySchema ¶
type ArraySchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
ArraySchema validates array/slice values.
func (*ArraySchema) Custom ¶
func (s *ArraySchema) Custom(fn queryfy.ValidatorFunc) *ArraySchema
Custom adds a custom validator function.
func (*ArraySchema) Length ¶
func (s *ArraySchema) Length(length int) *ArraySchema
Length sets both minimum and maximum items to the same value.
func (*ArraySchema) MaxItems ¶
func (s *ArraySchema) MaxItems(max int) *ArraySchema
MaxItems sets the maximum number of items.
func (*ArraySchema) MinItems ¶
func (s *ArraySchema) MinItems(min int) *ArraySchema
MinItems sets the minimum number of items.
func (*ArraySchema) Nullable ¶
func (s *ArraySchema) Nullable() *ArraySchema
Nullable allows the field to be null.
func (*ArraySchema) Of ¶
func (s *ArraySchema) Of(schema queryfy.Schema) *ArraySchema
Of sets the schema for array elements.
func (*ArraySchema) Optional ¶
func (s *ArraySchema) Optional() *ArraySchema
Optional marks the field as optional (default).
func (*ArraySchema) Required ¶
func (s *ArraySchema) Required() *ArraySchema
Required marks the field as required.
func (*ArraySchema) Transform ¶ added in v0.2.0
func (s *ArraySchema) Transform(transformer Transformer) *TransformSchema
Transform adds transformation capability to ArraySchema.
func (*ArraySchema) Type ¶
func (s *ArraySchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*ArraySchema) UniqueItems ¶
func (s *ArraySchema) UniqueItems() *ArraySchema
UniqueItems requires all items to be unique.
func (*ArraySchema) Validate ¶
func (s *ArraySchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
type BoolSchema ¶
type BoolSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
BoolSchema validates boolean values.
func (*BoolSchema) Custom ¶
func (s *BoolSchema) Custom(fn queryfy.ValidatorFunc) *BoolSchema
Custom adds a custom validator function.
func (*BoolSchema) Nullable ¶
func (s *BoolSchema) Nullable() *BoolSchema
Nullable allows the field to be null.
func (*BoolSchema) Optional ¶
func (s *BoolSchema) Optional() *BoolSchema
Optional marks the field as optional (default).
func (*BoolSchema) Required ¶
func (s *BoolSchema) Required() *BoolSchema
Required marks the field as required.
func (*BoolSchema) Transform ¶ added in v0.2.0
func (s *BoolSchema) Transform(transformer Transformer) *TransformSchema
Transform adds transformation capability to BoolSchema.
func (*BoolSchema) Type ¶
func (s *BoolSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*BoolSchema) Validate ¶
func (s *BoolSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
type CustomSchema ¶
type CustomSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
CustomSchema allows custom validation logic.
func Custom ¶
func Custom(validator queryfy.ValidatorFunc) *CustomSchema
Custom creates a new custom schema with a validator function.
func (*CustomSchema) Nullable ¶
func (s *CustomSchema) Nullable() *CustomSchema
Nullable allows the field to be null.
func (*CustomSchema) Optional ¶
func (s *CustomSchema) Optional() *CustomSchema
Optional marks the field as optional (default).
func (*CustomSchema) Required ¶
func (s *CustomSchema) Required() *CustomSchema
Required marks the field as required.
func (*CustomSchema) Type ¶
func (s *CustomSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*CustomSchema) Validate ¶
func (s *CustomSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
type DateTimeSchema ¶
type DateTimeSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
DateTimeSchema validates date/time values.
func (*DateTimeSchema) Age ¶
func (s *DateTimeSchema) Age(minAge, maxAge int) *DateTimeSchema
Age validates that the date represents an age within the specified range. Useful for birth dates.
func (*DateTimeSchema) Between ¶
func (s *DateTimeSchema) Between(min, max time.Time) *DateTimeSchema
Between sets both minimum and maximum date/time.
func (*DateTimeSchema) BetweenStrings ¶
func (s *DateTimeSchema) BetweenStrings(min, max string) *DateTimeSchema
BetweenStrings sets both minimum and maximum date/time from strings.
func (*DateTimeSchema) BusinessDay ¶
func (s *DateTimeSchema) BusinessDay() *DateTimeSchema
BusinessDay validates that the date is a business day (Mon-Fri).
func (*DateTimeSchema) Custom ¶
func (s *DateTimeSchema) Custom(fn queryfy.ValidatorFunc) *DateTimeSchema
Custom adds a custom validator function.
func (*DateTimeSchema) DMY ¶
func (s *DateTimeSchema) DMY() *DateTimeSchema
DMY sets the format to DD/MM/YYYY (used in UK, Europe, Latin America, and most of the world).
func (*DateTimeSchema) DateOnly ¶
func (s *DateTimeSchema) DateOnly() *DateTimeSchema
DateOnly sets the format to date only (YYYY-MM-DD).
func (*DateTimeSchema) Format ¶
func (s *DateTimeSchema) Format(format string) *DateTimeSchema
Format sets the expected date/time format. Common formats:
- time.RFC3339: "2006-01-02T15:04:05Z07:00"
- time.DateOnly: "2006-01-02"
- "2006-01-02 15:04:05"
- "01/02/2006"
- "02-Jan-2006"
func (*DateTimeSchema) Future ¶
func (s *DateTimeSchema) Future() *DateTimeSchema
Future requires the date/time to be in the future.
func (*DateTimeSchema) ISO8601 ¶
func (s *DateTimeSchema) ISO8601() *DateTimeSchema
ISO8601 sets the format to ISO8601 (RFC3339).
func (*DateTimeSchema) MDY ¶
func (s *DateTimeSchema) MDY() *DateTimeSchema
MDY sets the format to MM/DD/YYYY (used primarily in the US).
func (*DateTimeSchema) Max ¶
func (s *DateTimeSchema) Max(max time.Time) *DateTimeSchema
Max sets the maximum allowed date/time.
func (*DateTimeSchema) MaxString ¶
func (s *DateTimeSchema) MaxString(max string) *DateTimeSchema
MaxString sets the maximum allowed date/time from a string.
func (*DateTimeSchema) Min ¶
func (s *DateTimeSchema) Min(min time.Time) *DateTimeSchema
Min sets the minimum allowed date/time.
func (*DateTimeSchema) MinString ¶
func (s *DateTimeSchema) MinString(min string) *DateTimeSchema
MinString sets the minimum allowed date/time from a string.
func (*DateTimeSchema) Nullable ¶
func (s *DateTimeSchema) Nullable() *DateTimeSchema
Nullable allows the field to be null.
func (*DateTimeSchema) Optional ¶
func (s *DateTimeSchema) Optional() *DateTimeSchema
Optional marks the field as optional (default).
func (*DateTimeSchema) Past ¶
func (s *DateTimeSchema) Past() *DateTimeSchema
Past requires the date/time to be in the past.
func (*DateTimeSchema) Required ¶
func (s *DateTimeSchema) Required() *DateTimeSchema
Required marks the field as required.
func (*DateTimeSchema) Transform ¶ added in v0.2.0
func (s *DateTimeSchema) Transform(transformer Transformer) *TransformSchema
Transform adds transformation capability to DateTimeSchema.
func (*DateTimeSchema) Type ¶
func (s *DateTimeSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*DateTimeSchema) Validate ¶
func (s *DateTimeSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
func (*DateTimeSchema) Weekday ¶
func (s *DateTimeSchema) Weekday(days ...time.Weekday) *DateTimeSchema
Weekday validates that the date falls on specific weekdays.
func (*DateTimeSchema) YMD ¶
func (s *DateTimeSchema) YMD() *DateTimeSchema
YMD sets the format to YYYY-MM-DD (ISO format).
type DependencyCondition ¶ added in v0.2.0
DependencyCondition is a function that receives the parent object and returns whether the dependent validation should be applied.
func WhenAll ¶ added in v0.2.0
func WhenAll(conditions ...DependencyCondition) DependencyCondition
WhenAll creates a condition that requires all sub-conditions to be true.
func WhenAny ¶ added in v0.2.0
func WhenAny(conditions ...DependencyCondition) DependencyCondition
WhenAny creates a condition that requires at least one sub-condition to be true.
func WhenEquals ¶ added in v0.2.0
func WhenEquals(field string, value interface{}) DependencyCondition
WhenEquals creates a condition that checks if a field equals a specific value.
func WhenExists ¶ added in v0.2.0
func WhenExists(field string) DependencyCondition
WhenExists creates a condition that checks if a field exists and is not nil.
func WhenFalse ¶ added in v0.2.0
func WhenFalse(field string) DependencyCondition
WhenFalse creates a condition that checks if a boolean field is false.
func WhenGreaterThan ¶ added in v0.2.0
func WhenGreaterThan(field string, threshold float64) DependencyCondition
WhenGreaterThan creates a condition for numeric comparisons.
func WhenIn ¶ added in v0.2.0
func WhenIn(field string, values ...interface{}) DependencyCondition
WhenIn creates a condition that checks if a field's value is in a list.
func WhenLessThan ¶ added in v0.2.0
func WhenLessThan(field string, threshold float64) DependencyCondition
WhenLessThan creates a condition for numeric comparisons.
func WhenNotEquals ¶ added in v0.2.0
func WhenNotEquals(field string, value interface{}) DependencyCondition
WhenNotEquals creates a condition that checks if a field does not equal a specific value.
func WhenNotExists ¶ added in v0.2.0
func WhenNotExists(field string) DependencyCondition
WhenNotExists creates a condition that checks if a field does not exist or is nil.
func WhenTrue ¶ added in v0.2.0
func WhenTrue(field string) DependencyCondition
WhenTrue creates a condition that checks if a boolean field is true.
type DependentSchema ¶ added in v0.2.0
type DependentSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
DependentSchema validates fields based on conditions from other fields.
func Dependent ¶ added in v0.2.0
func Dependent(fieldName string) *DependentSchema
Dependent creates a new dependent field schema.
func RequiredUnless ¶ added in v0.2.0
func RequiredUnless(condition DependencyCondition, schema queryfy.Schema) *DependentSchema
RequiredUnless creates a schema that makes a field required unless a condition is met.
func RequiredWhen ¶ added in v0.2.0
func RequiredWhen(condition DependencyCondition, schema queryfy.Schema) *DependentSchema
RequiredWhen creates a schema that makes a field required when a condition is met.
func (*DependentSchema) Custom ¶ added in v0.2.0
func (s *DependentSchema) Custom(fn queryfy.ValidatorFunc) *DependentSchema
Custom adds a custom validator function.
func (*DependentSchema) Else ¶ added in v0.2.0
func (s *DependentSchema) Else(elseSchema queryfy.Schema) *DependentSchema
Else sets the schema to apply when the condition is false.
func (*DependentSchema) On ¶ added in v0.2.0
func (s *DependentSchema) On(fields ...string) *DependentSchema
On specifies which fields this validation depends on.
func (*DependentSchema) Optional ¶ added in v0.2.0
func (s *DependentSchema) Optional() *DependentSchema
Optional marks the field as optional.
func (*DependentSchema) Required ¶ added in v0.2.0
func (s *DependentSchema) Required() *DependentSchema
Required marks the field as required (when the condition is met).
func (*DependentSchema) Then ¶ added in v0.2.0
func (s *DependentSchema) Then(schema queryfy.Schema) *DependentSchema
Then sets the schema to apply when the condition is true.
func (*DependentSchema) Type ¶ added in v0.2.0
func (s *DependentSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*DependentSchema) Validate ¶ added in v0.2.0
func (s *DependentSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
func (*DependentSchema) ValidateWithParent ¶ added in v0.2.0
func (s *DependentSchema) ValidateWithParent(value interface{}, parentData map[string]interface{}, ctx *queryfy.ValidationContext) error
ValidateWithParent validates the field considering the parent object context.
func (*DependentSchema) When ¶ added in v0.2.0
func (s *DependentSchema) When(condition DependencyCondition) *DependentSchema
When sets the condition function that determines when validation applies.
type NotSchema ¶
type NotSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
NotSchema inverts the result of another schema.
func (*NotSchema) Type ¶
func (s *NotSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
type NumberSchema ¶
type NumberSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
NumberSchema validates numeric values.
func (*NumberSchema) Custom ¶
func (s *NumberSchema) Custom(fn queryfy.ValidatorFunc) *NumberSchema
Custom adds a custom validator function.
func (*NumberSchema) Integer ¶
func (s *NumberSchema) Integer() *NumberSchema
Integer validates that the number is an integer (no decimal part).
func (*NumberSchema) Max ¶
func (s *NumberSchema) Max(max float64) *NumberSchema
Max sets the maximum value (inclusive).
func (*NumberSchema) Min ¶
func (s *NumberSchema) Min(min float64) *NumberSchema
Min sets the minimum value (inclusive).
func (*NumberSchema) MultipleOf ¶
func (s *NumberSchema) MultipleOf(value float64) *NumberSchema
MultipleOf validates that the number is a multiple of the given value.
func (*NumberSchema) Negative ¶
func (s *NumberSchema) Negative() *NumberSchema
Negative validates that the number is negative (< 0).
func (*NumberSchema) Nullable ¶
func (s *NumberSchema) Nullable() *NumberSchema
Nullable allows the field to be null.
func (*NumberSchema) Optional ¶
func (s *NumberSchema) Optional() *NumberSchema
Optional marks the field as optional (default).
func (*NumberSchema) Positive ¶
func (s *NumberSchema) Positive() *NumberSchema
Positive validates that the number is positive (> 0).
func (*NumberSchema) Range ¶
func (s *NumberSchema) Range(min, max float64) *NumberSchema
Range sets both minimum and maximum values.
func (*NumberSchema) Required ¶
func (s *NumberSchema) Required() *NumberSchema
Required marks the field as required.
func (*NumberSchema) Transform ¶ added in v0.2.0
func (s *NumberSchema) Transform(transformer Transformer) *TransformSchema
Transform adds transformation capability to NumberSchema.
func (*NumberSchema) Type ¶
func (s *NumberSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*NumberSchema) Validate ¶
func (s *NumberSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
type ObjectSchema ¶
type ObjectSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
ObjectSchema validates object/map values.
func (*ObjectSchema) Custom ¶
func (s *ObjectSchema) Custom(fn queryfy.ValidatorFunc) *ObjectSchema
Custom adds a custom validator function.
func (*ObjectSchema) Field ¶
func (s *ObjectSchema) Field(name string, schema queryfy.Schema) *ObjectSchema
Field adds a field schema to the object.
func (*ObjectSchema) FieldNames ¶
func (s *ObjectSchema) FieldNames() []string
FieldNames returns the names of all defined fields.
func (*ObjectSchema) Fields ¶
func (s *ObjectSchema) Fields(fields map[string]queryfy.Schema) *ObjectSchema
Fields adds multiple field schemas at once.
func (*ObjectSchema) Nullable ¶
func (s *ObjectSchema) Nullable() *ObjectSchema
Nullable allows the field to be null.
func (*ObjectSchema) Optional ¶
func (s *ObjectSchema) Optional() *ObjectSchema
Optional marks the object as optional (default).
func (*ObjectSchema) Required ¶
func (s *ObjectSchema) Required() *ObjectSchema
Required marks the object itself as required.
func (*ObjectSchema) RequiredFields ¶
func (s *ObjectSchema) RequiredFields(names ...string) *ObjectSchema
RequiredFields marks specific fields as required. This overrides the required status set on individual field schemas.
func (*ObjectSchema) String ¶
func (s *ObjectSchema) String() string
String returns a string representation of the object schema.
func (*ObjectSchema) Transform ¶ added in v0.2.0
func (s *ObjectSchema) Transform(transformer Transformer) *TransformSchema
Transform adds transformation capability to ObjectSchema.
func (*ObjectSchema) Type ¶
func (s *ObjectSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*ObjectSchema) Validate ¶
func (s *ObjectSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
func (*ObjectSchema) WithDependencies ¶ added in v0.2.0
func (s *ObjectSchema) WithDependencies() *ObjectSchemaWithDependencies
WithDependencies converts an ObjectSchema to support dependent field validation.
type ObjectSchemaWithDependencies ¶ added in v0.2.0
type ObjectSchemaWithDependencies struct {
*ObjectSchema
// contains filtered or unexported fields
}
ObjectSchemaWithDependencies extends the regular ObjectSchema to support dependent fields.
func (*ObjectSchemaWithDependencies) Custom ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) Custom(fn queryfy.ValidatorFunc) *ObjectSchemaWithDependencies
Custom adds a custom validator (override to return correct type).
func (*ObjectSchemaWithDependencies) DependentField ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) DependentField(name string, dependent *DependentSchema) *ObjectSchemaWithDependencies
DependentField adds a dependent field to the schema.
func (*ObjectSchemaWithDependencies) Field ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) Field(name string, schema queryfy.Schema) *ObjectSchemaWithDependencies
Field adds a regular field to the schema (override to return correct type).
func (*ObjectSchemaWithDependencies) Fields ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) Fields(fields map[string]queryfy.Schema) *ObjectSchemaWithDependencies
Fields adds multiple fields at once (override to return correct type).
func (*ObjectSchemaWithDependencies) Nullable ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) Nullable() *ObjectSchemaWithDependencies
Nullable allows the object to be null (override to return correct type).
func (*ObjectSchemaWithDependencies) Optional ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) Optional() *ObjectSchemaWithDependencies
Optional marks the object as optional (override to return correct type).
func (*ObjectSchemaWithDependencies) Required ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) Required() *ObjectSchemaWithDependencies
Required marks the object as required (override to return correct type).
func (*ObjectSchemaWithDependencies) RequiredFields ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) RequiredFields(names ...string) *ObjectSchemaWithDependencies
RequiredFields marks specific fields as required (override to return correct type).
func (*ObjectSchemaWithDependencies) Validate ¶ added in v0.2.0
func (s *ObjectSchemaWithDependencies) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate overrides the base validate to handle dependent fields.
type OrSchema ¶
type OrSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
OrSchema validates that at least one schema passes.
func (*OrSchema) Type ¶
func (s *OrSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
type StringSchema ¶
type StringSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
StringSchema validates string values.
func (*StringSchema) Custom ¶
func (s *StringSchema) Custom(fn queryfy.ValidatorFunc) *StringSchema
Custom adds a custom validator function.
func (*StringSchema) Email ¶
func (s *StringSchema) Email() *StringSchema
Email validates that the string is a valid email address.
func (*StringSchema) Enum ¶
func (s *StringSchema) Enum(values ...string) *StringSchema
Enum restricts the string to one of the specified values.
func (*StringSchema) Length ¶
func (s *StringSchema) Length(length int) *StringSchema
Length sets both minimum and maximum length to the same value.
func (*StringSchema) MaxLength ¶
func (s *StringSchema) MaxLength(max int) *StringSchema
MaxLength sets the maximum string length.
func (*StringSchema) MinLength ¶
func (s *StringSchema) MinLength(min int) *StringSchema
MinLength sets the minimum string length.
func (*StringSchema) Nullable ¶
func (s *StringSchema) Nullable() *StringSchema
Nullable allows the field to be null.
func (*StringSchema) Optional ¶
func (s *StringSchema) Optional() *StringSchema
Optional marks the field as optional (default).
func (*StringSchema) Pattern ¶
func (s *StringSchema) Pattern(pattern string) *StringSchema
Pattern sets a regular expression pattern that the string must match.
func (*StringSchema) Required ¶
func (s *StringSchema) Required() *StringSchema
Required marks the field as required.
func (*StringSchema) Transform ¶ added in v0.2.0
func (s *StringSchema) Transform(transformer Transformer) *TransformSchema
Transform adds transformation capability to StringSchema.
func (*StringSchema) Type ¶
func (s *StringSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*StringSchema) URL ¶
func (s *StringSchema) URL() *StringSchema
URL validates that the string is a valid URL.
func (*StringSchema) UUID ¶
func (s *StringSchema) UUID() *StringSchema
UUID validates that the string is a valid UUID.
func (*StringSchema) Validate ¶
func (s *StringSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
type TransformSchema ¶ added in v0.2.0
type TransformSchema struct {
queryfy.BaseSchema
// contains filtered or unexported fields
}
TransformSchema adds transformation capabilities to any schema.
func Transform ¶ added in v0.2.0
func Transform(schema queryfy.Schema) *TransformSchema
Transform creates a new transform schema wrapping an existing schema.
func (*TransformSchema) Add ¶ added in v0.2.0
func (s *TransformSchema) Add(transformer Transformer) *TransformSchema
Add adds a transformer to the pipeline.
func (*TransformSchema) Optional ¶ added in v0.2.0
func (s *TransformSchema) Optional() *TransformSchema
Optional marks the field as optional.
func (*TransformSchema) Required ¶ added in v0.2.0
func (s *TransformSchema) Required() *TransformSchema
Required marks the field as required.
func (*TransformSchema) Type ¶ added in v0.2.0
func (s *TransformSchema) Type() queryfy.SchemaType
Type implements the Schema interface.
func (*TransformSchema) Validate ¶ added in v0.2.0
func (s *TransformSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
Validate implements the Schema interface.
func (*TransformSchema) ValidateAndTransform ¶ added in v0.2.0
func (s *TransformSchema) ValidateAndTransform(value interface{}, ctx *queryfy.ValidationContext) (interface{}, error)
ValidateAndTransform validates and returns the transformed value.
type Transformer ¶ added in v0.2.0
type Transformer func(value interface{}) (interface{}, error)
Transformer is a function that transforms a value. It returns the transformed value and any error.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
common.go - Common transformation functions
|
common.go - Common transformation functions |