Documentation
¶
Index ¶
- Variables
- type Address
- type AllNumericTypes
- type BoolExample
- type CloudNativeService
- type Config
- type CrossPackageFieldOnlyExample
- type DNS1123Example
- type DefaultExample
- type EnumExample
- type FormatExample
- type KubernetesName
- type KubernetesResource
- type KubernetesResourceSpec
- type NetworkConfig
- type NumericOneofExample
- type OrderStatus
- type PodContainerSpec
- type PodSpec
- type PointerExample
- type Priority
- type Product
- type SliceExample
- type Status
- type StringEnumExample
- type StringEqNeExample
- type StringPatterns
- type StringPriorityExample
- type User
Constants ¶
This section is empty.
Variables ¶
var OrderStatusEnums = _OrderStatusEnums{ // contains filtered or unexported fields }
OrderStatusEnums is the enum helper for OrderStatus.
var PriorityEnums = _PriorityEnums{ // contains filtered or unexported fields }
PriorityEnums is the enum helper for Priority.
Functions ¶
This section is empty.
Types ¶
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 CloudNativeService ¶ added in v0.3.6
type CloudNativeService struct {
// validategen:@required
// validategen:@dns1123_label
// Service domain name (e.g., "api.service.cloud.example.com")
DomainName string
// validategen:@required
// validategen:@dns1123_label
// Service instance name (e.g., "api-service-01")
InstanceName string
// validategen:@required
// validategen:@dns1123_label
// Container registry hostname (e.g., "registry.example.com")
RegistryHost string
}
CloudNativeService demonstrates DNS label validation for cloud-native service naming. validategen:@validate
func (CloudNativeService) Validate ¶ added in v0.3.6
func (x CloudNativeService) Validate() error
Validate validates the CloudNativeService 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
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 DNS1123Example ¶ added in v0.3.6
type DNS1123Example struct {
// validategen:@required
// validategen:@dns1123_label
Hostname string
// validategen:@required
// validategen:@dns1123_label
ServiceName string
// validategen:@required
// validategen:@dns1123_label
PodName string
}
DNS1123Example demonstrates @dns1123_label annotation for DNS label name validation. DNS label is based on RFC 1123 and commonly used in Kubernetes and cloud-native applications. validategen:@validate
func (DNS1123Example) Validate ¶ added in v0.3.6
func (x DNS1123Example) Validate() error
Validate validates the DNS1123Example fields.
type DefaultExample ¶ added in v0.3.5
type DefaultExample struct {
// validategen:@default(localhost)
Host string
// validategen:@default(8080)
Port int
// validategen:@default(true)
Enabled bool
// validategen:@default(1.5)
Version float64
// validategen:@default(unknown)
// validategen:@required
Name string
// validategen:@default(100)
// validategen:@min(0)
// validategen:@max(1000)
Count int64
}
DefaultExample demonstrates default value annotations. validategen:@validate
func (*DefaultExample) SetDefaults ¶ added in v0.3.5
func (x *DefaultExample) SetDefaults()
SetDefaults sets default values for zero-value fields.
func (DefaultExample) Validate ¶ added in v0.3.5
func (x DefaultExample) Validate() error
Validate validates the DefaultExample 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 KubernetesName ¶ added in v0.3.6
type KubernetesName struct {
// validategen:@required
// validategen:@dns1123_label
// Kubernetes namespace name
Namespace string
// validategen:@required
// validategen:@dns1123_label
// Kubernetes pod name
Pod string
// validategen:@required
// validategen:@dns1123_label
// Kubernetes service name
Service string
// validategen:@required
// validategen:@dns1123_label
// StatefulSet name
StatefulSetName string
}
KubernetesName demonstrates DNS label validation for Kubernetes naming conventions. validategen:@validate
func (KubernetesName) Validate ¶ added in v0.3.6
func (x KubernetesName) Validate() error
Validate validates the KubernetesName fields.
type KubernetesResource ¶ added in v0.3.6
type KubernetesResource struct {
// validategen:@cpu
CPURequest string
// validategen:@cpu
CPULimit string
// validategen:@memory
MemoryRequest string
// validategen:@memory
MemoryLimit string
}
KubernetesResource demonstrates CPU and memory validation for Kubernetes resources. validategen:@validate
func (KubernetesResource) Validate ¶ added in v0.3.6
func (x KubernetesResource) Validate() error
Validate validates the KubernetesResource fields.
type KubernetesResourceSpec ¶ added in v0.3.6
type KubernetesResourceSpec struct {
// validategen:@required
// validategen:@cpu
CPURequest string
// validategen:@cpu
CPULimit string
// validategen:@required
// validategen:@memory
MemoryRequest string
// validategen:@memory
MemoryLimit string
}
KubernetesResourceSpec demonstrates CPU and memory validation for Kubernetes resources. Example usage:
spec := KubernetesResourceSpec{
CPURequest: "500m", // Valid: 500 millicores
CPULimit: "1000m", // Valid: 1000 millicores
MemoryRequest: "512Mi", // Valid: 512 megabytes
MemoryLimit: "2Gi", // Valid: 2 gigabytes
}
if err := spec.Validate(); err != nil {
log.Fatal(err)
}
The @cpu and @memory annotations validate Kubernetes resource quantities: - @cpu validates CPU quantities (valid units: m, cores, or scientific notation) - @memory validates memory quantities (valid units: Ki, Mi, Gi, Ti, Pi, Ei, or bytes) validategen:@validate
func (KubernetesResourceSpec) Validate ¶ added in v0.3.6
func (x KubernetesResourceSpec) Validate() error
Validate validates the KubernetesResourceSpec 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 PodContainerSpec ¶ added in v0.3.6
type PodContainerSpec struct {
// validategen:@required
// validategen:@min(1)
Name string
// validategen:@required
Image string
// Container resource requests (required)
// validategen:@required
// validategen:@cpu
CPURequest string
// validategen:@required
// validategen:@memory
MemoryRequest string
// Container resource limits (optional but validated if provided)
// validategen:@cpu
CPULimit string
// validategen:@memory
MemoryLimit string
// validategen:@disk
DiskRequest string
// validategen:@disk
DiskLimit string
}
PodContainerSpec demonstrates a complete container specification with resource validation. Example usage:
container := PodContainerSpec{
Name: "nginx",
Image: "nginx:latest",
CPURequest: "100m", // Required: 100 millicores
MemoryRequest: "128Mi", // Required: 128 megabytes
CPULimit: "500m", // Optional: 500 millicores
MemoryLimit: "512Mi", // Optional: 512 megabytes
}
if err := container.Validate(); err != nil {
log.Fatal(err)
}
validategen:@validate
func (PodContainerSpec) Validate ¶ added in v0.3.6
func (x PodContainerSpec) Validate() error
Validate validates the PodContainerSpec fields.
type PodSpec ¶ added in v0.3.6
type PodSpec struct {
// validategen:@required
// validategen:@min(1)
// validategen:@max(63)
Name string
// Container resource requests
// validategen:@cpu
ContainerCPURequest string
// validategen:@memory
ContainerMemoryRequest string
// Container resource limits (optional but validated if provided)
// validategen:@cpu
ContainerCPULimit string
// validategen:@memory
ContainerMemoryLimit string
}
PodSpec demonstrates a complete Kubernetes pod specification with resource validation. validategen:@validate
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 Priority ¶ added in v0.3.6
type Priority string
Priority is a string enum type for testing string-based oneof_enum validation. enumgen:@enum(string)
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
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 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 StringPriorityExample ¶ added in v0.3.6
type StringPriorityExample struct {
// validategen:@oneof_enum(Priority)
Priority Priority
// validategen:@oneof_enum(Priority)
PriorityStr string
}
StringPriorityExample demonstrates oneof_enum validation with string enum type. validategen:@validate
func (StringPriorityExample) Validate ¶ added in v0.3.6
func (x StringPriorityExample) Validate() error
Validate validates the StringPriorityExample 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