examples

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OrderStatusEnums = _OrderStatusEnums{
	// contains filtered or unexported fields
}

OrderStatusEnums is the enum helper for OrderStatus.

Functions

This section is empty.

Types

type Address

type Address struct {
	Street string
	City   string
}

Address represents a user address.

func (Address) Validate

func (a Address) Validate() error

Validate validates the Address fields.

type AllNumericTypes

type AllNumericTypes struct {
	// validategen:@gt(0)
	Int int

	// validategen:@gt(0)
	Int8 int8

	// validategen:@gt(0)
	Int16 int16

	// validategen:@gt(0)
	Int32 int32

	// validategen:@gt(0)
	Int64 int64

	// validategen:@gt(0)
	Uint uint

	// validategen:@gt(0)
	Uint8 uint8

	// validategen:@gt(0)
	Uint16 uint16

	// validategen:@gt(0)
	Uint32 uint32

	// validategen:@gt(0)
	Uint64 uint64

	// validategen:@gt(0)
	Float32 float32

	// validategen:@gt(0)
	Float64 float64

	// validategen:@gt(0)
	Byte byte

	// validategen:@gt(0)
	Rune rune

	// validategen:@gt(0)
	Uintptr uintptr
}

AllNumericTypes demonstrates all supported numeric types. validategen:@validate

func (AllNumericTypes) Validate

func (x AllNumericTypes) Validate() error

Validate validates the AllNumericTypes fields.

type BoolExample

type BoolExample struct {
	// validategen:@required
	IsActive bool

	// validategen:@eq(true)
	MustBeTrue bool

	// validategen:@ne(true)
	MustBeFalse bool
}

BoolExample demonstrates bool validation. validategen:@validate

func (BoolExample) Validate

func (x BoolExample) Validate() error

Validate validates the BoolExample fields.

type Config

type Config struct {
	// validategen:@required
	Host string

	// validategen:@required
	// validategen:@min(1)
	// validategen:@max(65535)
	Port int

	// validategen:@min(1)
	Tags []string

	// validategen:@oneof(debug, info, warn, error)
	LogLevel string
}

Config represents application config. validategen:@validate

func (Config) Validate

func (x Config) Validate() error

Validate validates the Config fields.

type CrossPackageFieldOnlyExample added in v0.3.2

type CrossPackageFieldOnlyExample struct {
	// validategen:@required
	// validategen:@min(1)
	// validategen:@max(10)
	Scores []common.Priority
}

CrossPackageFieldOnlyExample demonstrates validation with only cross-package field types (no oneof_enum). validategen:@validate

func (CrossPackageFieldOnlyExample) Validate added in v0.3.2

func (x CrossPackageFieldOnlyExample) Validate() error

Validate validates the CrossPackageFieldOnlyExample fields.

type EnumExample added in v0.3.1

type EnumExample struct {
	// validategen:@oneof_enum(OrderStatus)
	Status OrderStatus
}

EnumExample demonstrates oneof_enum validation. validategen:@validate

func (EnumExample) Validate added in v0.3.1

func (x EnumExample) Validate() error

Validate validates the EnumExample fields.

type FormatExample

type FormatExample struct {
	// validategen:@format(json)
	JSONConfig string

	// validategen:@format(yaml)
	YAMLConfig string

	// validategen:@format(toml)
	TOMLConfig string

	// validategen:@format(csv)
	CSVData string
}

FormatExample demonstrates format validation annotations. validategen:@validate

func (FormatExample) Validate

func (x FormatExample) Validate() error

Validate validates the FormatExample fields.

type NetworkConfig

type NetworkConfig struct {
	// validategen:@ipv4
	IPv4Address string

	// validategen:@ipv6
	IPv6Address string

	// validategen:@ip
	AnyIPAddress string

	// validategen:@duration
	Timeout string

	// validategen:@duration
	// validategen:@duration_min(1s)
	// validategen:@duration_max(1h)
	RetryInterval string

	// validategen:@duration_min(100ms)
	// validategen:@duration_max(30s)
	RequestTimeout string
}

NetworkConfig demonstrates IP validation annotations. validategen:@validate

func (NetworkConfig) Validate

func (x NetworkConfig) Validate() error

Validate validates the NetworkConfig fields.

type NumericOneofExample added in v0.3.1

type NumericOneofExample struct {
	// validategen:@oneof(1 2 3 4 5)
	Priority int

	// validategen:@oneof(100 200 300)
	StatusCode int64
}

NumericOneofExample demonstrates oneof on numeric type. validategen:@validate

func (NumericOneofExample) Validate added in v0.3.1

func (x NumericOneofExample) Validate() error

Validate validates the NumericOneofExample fields.

type OrderStatus added in v0.3.1

type OrderStatus int

OrderStatus is an enum type for testing oneof_enum. enumgen:@enum(string)

const (
	OrderStatusPending OrderStatus = iota + 1
	OrderStatusPaid
	OrderStatusShipped
	OrderStatusDelivered
)

func (OrderStatus) IsValid added in v0.3.1

func (x OrderStatus) IsValid() bool

IsValid reports whether x is a valid OrderStatus.

func (OrderStatus) String added in v0.3.1

func (x OrderStatus) String() string

String returns the string representation of OrderStatus.

type PointerExample added in v0.3.1

type PointerExample struct {
	// validategen:@min(2)
	// validategen:@max(10)
	OptionalName *string

	// validategen:@min(0)
	// validategen:@max(100)
	OptionalAge *int

	// validategen:@min(0.0)
	// validategen:@max(100.0)
	OptionalScore *float64
}

PointerExample demonstrates pointer type validation. validategen:@validate

func (PointerExample) Validate added in v0.3.1

func (x PointerExample) Validate() error

Validate validates the PointerExample fields.

type Product

type Product struct {
	// validategen:@required
	// validategen:@gt(0)
	ID int64

	// validategen:@required
	Name string

	// validategen:@gte(0)
	Price float64

	// validategen:@eq(1)
	Version int

	// validategen:@ne(0)
	Stock int

	// validategen:@lt(100)
	Discount float32

	// validategen:@lte(1000)
	Weight uint
}

Product demonstrates numeric comparison annotations. validategen:@validate

func (Product) Validate

func (x Product) Validate() error

Validate validates the Product fields.

type SliceExample

type SliceExample struct {
	// validategen:@required
	// validategen:@min(1)
	// validategen:@max(10)
	Items []string

	// validategen:@len(3)
	FixedItems []int

	// validategen:@required
	RequiredMap map[string]int
}

SliceExample demonstrates slice validation. validategen:@validate

func (SliceExample) Validate

func (x SliceExample) Validate() error

Validate validates the SliceExample fields.

type Status

type Status int

Status is a custom int type with validation.

func (Status) Validate

func (s Status) Validate() error

Validate validates the Status value.

type StringEnumExample added in v0.3.2

type StringEnumExample struct {
	// validategen:@oneof_enum(OrderStatus)
	StatusStr string
}

StringEnumExample demonstrates oneof_enum validation with string field type. validategen:@validate

func (StringEnumExample) Validate added in v0.3.2

func (x StringEnumExample) Validate() error

Validate validates the StringEnumExample fields.

type StringEqNeExample added in v0.3.1

type StringEqNeExample struct {
	// validategen:@eq(v1)
	Version string

	// validategen:@ne(banned)
	Status string
}

StringEqNeExample demonstrates eq/ne on string type. validategen:@validate

func (StringEqNeExample) Validate added in v0.3.1

func (x StringEqNeExample) Validate() error

Validate validates the StringEqNeExample fields.

type StringPatterns

type StringPatterns struct {
	// validategen:@alpha
	FirstName string

	// validategen:@alphanum
	Username string

	// validategen:@numeric
	PhoneNumber string

	// validategen:@contains(example)
	Email string

	// validategen:@excludes(admin)
	DisplayName string

	// validategen:@startswith(https://)
	SecureURL string

	// validategen:@endswith(.com)
	Domain string

	// validategen:@regex(^[A-Z]{2}-\d{4}$)
	ProductCode string
}

StringPatterns demonstrates string pattern annotations. validategen:@validate

func (StringPatterns) Validate

func (x StringPatterns) Validate() error

Validate validates the StringPatterns fields.

type User

type User struct {
	// validategen:@required
	// validategen:@gt(0)
	ID int64

	// validategen:@required
	// validategen:@min(2)
	// validategen:@max(50)
	Name string

	// validategen:@required
	// validategen:@email
	Email string

	// validategen:@gte(0)
	// validategen:@lte(150)
	Age int

	// validategen:@required
	// validategen:@min(8)
	Password string

	// validategen:@oneof(admin, user, guest)
	Role string

	// validategen:@url
	Website string

	// validategen:@uuid
	UUID string

	// validategen:@ip
	IP string

	// validategen:@alphanum
	// validategen:@len(6)
	Code string

	// validategen:@method(Validate)
	Address Address

	// validategen:@method(Validate)
	// validategen:@required
	OptionalAddress *Address

	// validategen:@method(Validate)
	Status Status

	// validategen:@method(Validate)
	Addresses []Address

	// validategen:@method(Validate)
	AddressMap map[string]Address
}

User represents a user model. validategen:@validate

func (User) Validate

func (x User) Validate() error

Validate validates the User fields.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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