builders

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2025 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Overview

datetime.go - Date/Time validation builder for Queryfy

Index

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 And

func And(schemas ...queryfy.Schema) *AndSchema

And creates a new AND schema that requires all sub-schemas to pass.

func (*AndSchema) Nullable

func (s *AndSchema) Nullable() *AndSchema

Nullable allows the field to be null.

func (*AndSchema) Optional

func (s *AndSchema) Optional() *AndSchema

Optional marks the field as optional (default).

func (*AndSchema) Required

func (s *AndSchema) Required() *AndSchema

Required marks the field as required.

func (*AndSchema) Type

func (s *AndSchema) Type() queryfy.SchemaType

Type implements the Schema interface.

func (*AndSchema) Validate

func (s *AndSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error

Validate implements the Schema interface.

type ArraySchema

type ArraySchema struct {
	queryfy.BaseSchema
	// contains filtered or unexported fields
}

ArraySchema validates array/slice values.

func Array

func Array() *ArraySchema

Array creates a new array schema builder.

func (*ArraySchema) Custom

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 Bool

func Bool() *BoolSchema

Bool creates a new boolean schema builder.

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 DateTime

func DateTime() *DateTimeSchema

DateTime creates a new date/time schema builder.

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

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 Not

func Not(schema queryfy.Schema) *NotSchema

Not creates a new NOT schema that inverts another schema's validation.

func (*NotSchema) Nullable

func (s *NotSchema) Nullable() *NotSchema

Nullable allows the field to be null.

func (*NotSchema) Optional

func (s *NotSchema) Optional() *NotSchema

Optional marks the field as optional (default).

func (*NotSchema) Required

func (s *NotSchema) Required() *NotSchema

Required marks the field as required.

func (*NotSchema) Type

func (s *NotSchema) Type() queryfy.SchemaType

Type implements the Schema interface.

func (*NotSchema) Validate

func (s *NotSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error

Validate implements the Schema interface.

type NumberSchema

type NumberSchema struct {
	queryfy.BaseSchema
	// contains filtered or unexported fields
}

NumberSchema validates numeric values.

func Number

func Number() *NumberSchema

Number creates a new number schema builder.

func (*NumberSchema) Custom

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 Object

func Object() *ObjectSchema

Object creates a new object schema builder.

func (*ObjectSchema) Custom

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 Or

func Or(schemas ...queryfy.Schema) *OrSchema

Or creates a new OR schema that requires at least one sub-schema to pass.

func (*OrSchema) Nullable

func (s *OrSchema) Nullable() *OrSchema

Nullable allows the field to be null.

func (*OrSchema) Optional

func (s *OrSchema) Optional() *OrSchema

Optional marks the field as optional (default).

func (*OrSchema) Required

func (s *OrSchema) Required() *OrSchema

Required marks the field as required.

func (*OrSchema) Type

func (s *OrSchema) Type() queryfy.SchemaType

Type implements the Schema interface.

func (*OrSchema) Validate

func (s *OrSchema) Validate(value interface{}, ctx *queryfy.ValidationContext) error

Validate implements the Schema interface.

type StringSchema

type StringSchema struct {
	queryfy.BaseSchema
	// contains filtered or unexported fields
}

StringSchema validates string values.

func String

func String() *StringSchema

String creates a new string schema builder.

func (*StringSchema) Custom

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL