package
Version:
v0.0.2
Opens a new window with list of versions in this module.
Published: Jan 16, 2026
License: Apache-2.0
Opens a new window with license information.
Imports: 11
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
ginx/validator
ginx/validator 是一个基于 Gin 和 go-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
¶
BindAndValid 通用绑定验证器
返回值 bool: true=通过, false=失败
返回值 map: 失败详情 (key=字段名, value=错误信息)
RegisterRule 提供给业务方注册自定义规则的入口
tag: 验证标签,如 "mobile"
msg: 错误提示模版,如 "手机号格式不正确"
fn: 验证函数逻辑
Source Files
¶
Click to show internal directories.
Click to hide internal directories.