validatorV2

package
v1.57.2 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterExFun added in v1.52.0

func RegisterExFun(key string, fn ExFn)

RegisterExFun 注册一个扩展校验函数,key 为 v-ex 标签中的键

func UnregisterExFun added in v1.52.0

func UnregisterExFun(key string)

UnregisterExFun 注销注册函数

func WithFiber

func WithFiber[T any](c *fiber.Ctx, fns ...func(ins any) (err error)) (T, error)

WithFiber 在 Fiber 框架中绑定并验证请求数据。

func WithGin

func WithGin[T any](c *gin.Context, fns ...func(ins any) (err error)) (T, error)

WithGin 在 Gin 框架中绑定并验证请求数据。

Types

type ExFn added in v1.52.3

type ExFn func(val any) error

ExFn 扩展校验函数类型及注册表

type FieldResult added in v1.52.0

type FieldResult struct {
	Field  string   `json:"field"`
	Errors []string `json:"errors"`
}

FieldResult 保留类型以兼容引用(目前不再返回 FieldResult)

type Validator

type Validator struct{}

func (Validator) Validate added in v1.52.0

func (Validator) Validate(data any, exFns ...func(d any) error) []error

Validate 验证任意结构体,返回每个字段的验证结果(字段名和错误切片)。 支持的 tag: - v-rule: 规则串,规则之间以分号分隔。例如: "required;min>3;max<10;email;in=a,b" - v-name: 字段可读名称,嵌套时会以点号拼接,例如: 父.子 设计假设: - min / max 对字符串表示长度(>= / <=),对数字表示数值(>= / <=)。 - in / not-in 使用逗号分隔的值列表。 - regex=... 使用完整正则表达式。 - 支持快捷规则: email, date(2006-01-02), time(15:04:05), datetime(2006-01-02 15:04:05)

Jump to

Keyboard shortcuts

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