validator

package
v0.0.2 Latest Latest
Warning

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

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

README

ginx/validator

ginx/validator 是一个基于 Gingo-playground/validator 的轻量级参数校验封装库。

它的核心目标是:让参数校验变得简单、直观且“开箱即用”。

✨ 特性

  • ⚡️ 开箱即用:自动初始化中文翻译器,自动配置 JSON Tag 优先。
  • 🌏 自动翻译:内置中文错误提示,无需手动编写翻译映射逻辑。
  • 🛡️ 格式统一:错误信息以 map[string]string 格式返回,Key 为 JSON 字段名,Value 为错误详情,前端友好。
  • 🔌 插件化扩展:提供 RegisterRule 接口,允许业务方在各模块中轻松注册自定义正则或逻辑。
  • 🚀 零侵入:完全兼容 Gin 原生 binding 标签。

📦 安装

go get -u [github.com/einscat/ab-go](https://github.com/einscat/ab-go)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindAndValid

func BindAndValid(c *gin.Context, obj any) (bool, map[string]string)

BindAndValid 通用绑定验证器 返回值 bool: true=通过, false=失败 返回值 map: 失败详情 (key=字段名, value=错误信息)

func RegisterRule

func RegisterRule(tag string, fn val.Func, msg string)

RegisterRule 提供给业务方注册自定义规则的入口 tag: 验证标签,如 "mobile" msg: 错误提示模版,如 "手机号格式不正确" fn: 验证函数逻辑

Types

This section is empty.

Jump to

Keyboard shortcuts

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