examples

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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
}

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 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
}

NetworkConfig demonstrates IP validation annotations. validategen:@validate

func (NetworkConfig) Validate

func (x NetworkConfig) Validate() error

Validate validates the NetworkConfig 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
}

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 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)
	OptionalAddress *Address

	// validategen:@method(Validate)
	Status Status
}

User represents a user model. validategen:@validate

func (User) Validate

func (x User) Validate() error

Validate validates the User fields.

Jump to

Keyboard shortcuts

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