Documentation
¶
Overview ¶
datetime.go - Date/Time validation builder 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) 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) 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) 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 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) 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) Type() queryfy.SchemaType
- func (s *ObjectSchema) 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) Type() queryfy.SchemaType
- func (s *StringSchema) URL() *StringSchema
- func (s *StringSchema) UUID() *StringSchema
- func (s *StringSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error
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) 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) 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) 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 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) 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) 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.
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) 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.