Documentation
¶
Overview ¶
Package validate 提供代码式、无 tag、无反射的请求参数校验规则。
设计约束:
- 规则是纯函数(Rule[T]),不接收 context,不访问数据库/仓储/外部服务;
- 不引入 reflect、DSL 或全局注册器;
- Validate 聚合每个字段的第一条失败规则,HTTP 入口通过 FirstError 只暴露第一条消息。
Index ¶
- func Field[T any](name string, value T, rules ...Rule[T]) fieldResult
- func FirstError(err error) error
- func Validate(fields ...fieldResult) error
- type Errors
- type FieldError
- type Rule
- func Email() Rule[string]
- func Max[T cmp.Ordered](bound T) Rule[T]
- func MaxItems[T any](n int) Rule[[]T]
- func MaxLen(n int) Rule[string]
- func Message[T any](msg string, rule Rule[T]) Rule[T]
- func Min[T cmp.Ordered](bound T) Rule[T]
- func MinItems[T any](n int) Rule[[]T]
- func MinLen(n int) Rule[string]
- func NotZero[T comparable]() Rule[T]
- func OneOf[T comparable](options ...T) Rule[T]
- func Optional[T any](rule Rule[T]) Rule[*T]
- func Required() Rule[string]
- func When[T any](cond bool, rule Rule[T]) Rule[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.