validator

package
v0.0.0-...-7fba91e Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatAsMap

func FormatAsMap(errors []Error) map[string]string

FormatAsMap 将验证错误转换为 map 格式

func FormatAsSlice

func FormatAsSlice(errors []Error) []string

FormatAsSlice 将验证错误转换为切片格式

func GetValidator

func GetValidator() *validator.Validate

GetValidator 获取全局验证器实例

func Init

func Init()

Init 初始化验证器并注册自定义验证规则

func Validate

func Validate(s interface{}) error

Validate 验证结构体

func ValidationErrorString

func ValidationErrorString(errors []Error) string

ValidationErrorString 将错误列表格式化为字符串

Types

type Error

type Error struct {
	Field   string `json:"field"`
	Message string `json:"message"`
	Tag     string `json:"tag,omitempty"`
}

Error 验证错误

func ParseError

func ParseError(err error) []Error

ParseError 解析验证错误,返回结构化的错误列表

func (Error) Error

func (e Error) Error() string

Error 实现 error 接口

Jump to

Keyboard shortcuts

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