validation

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package validation provides utilities for parsing and working with validation tags in go-bricks applications. It offers helpers for extracting validation metadata from struct types that can be used for both runtime validation and documentation generation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TagInfo

type TagInfo struct {
	Name        string            // Go field name
	JSONName    string            // JSON field name (from json tag)
	ParamType   string            // Parameter type: path, query, header, form, body
	ParamName   string            // Parameter name for path/query/header params
	Required    bool              // Whether field is required
	Constraints map[string]string // Validation constraints from validate tag
	Description string            // Documentation from doc tag
	Example     string            // Example value from example tag
	Tags        map[string]string // All struct tags for reference
}

TagInfo represents parsed validation tag information from a struct field

func ParseValidationTags

func ParseValidationTags(t reflect.Type) []TagInfo

ParseValidationTags extracts validation metadata from a struct type This function analyzes struct fields and their tags to build TagInfo objects that contain all validation and documentation metadata.

func (*TagInfo) GetConstraints

func (t *TagInfo) GetConstraints() map[string]string

GetConstraints returns all validation constraints

func (*TagInfo) GetEnum

func (t *TagInfo) GetEnum() ([]string, bool)

GetEnum returns enum values if present

func (*TagInfo) GetMax

func (t *TagInfo) GetMax() (int, bool)

GetMax returns the maximum value constraint if present

func (*TagInfo) GetMaxLength

func (t *TagInfo) GetMaxLength() (int, bool)

GetMaxLength returns the maximum length constraint if present

func (*TagInfo) GetMin

func (t *TagInfo) GetMin() (int, bool)

GetMin returns the minimum value constraint if present

func (*TagInfo) GetMinLength

func (t *TagInfo) GetMinLength() (int, bool)

GetMinLength returns the minimum length constraint if present

func (*TagInfo) GetPattern

func (t *TagInfo) GetPattern() (string, bool)

GetPattern returns the regex pattern constraint if present

func (*TagInfo) HasFormat

func (t *TagInfo) HasFormat(format string) bool

HasFormat returns true if the field has a specific format constraint

func (*TagInfo) IsEmail

func (t *TagInfo) IsEmail() bool

IsEmail returns true if the field has email validation

func (*TagInfo) IsRequired

func (t *TagInfo) IsRequired() bool

IsRequired returns true if the field has a required constraint

func (*TagInfo) IsURL

func (t *TagInfo) IsURL() bool

IsURL returns true if the field has URL validation

func (*TagInfo) IsUUID

func (t *TagInfo) IsUUID() bool

IsUUID returns true if the field has UUID validation

Jump to

Keyboard shortcuts

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