Documentation ¶
Overview ¶
Package filter 过滤器
提供了对数据的修正和验证功能。
Index ¶
- func And[T any](v ...func(T) bool) func(T) bool
- func Not[T any](v func(T) bool) func(T) bool
- func Or[T any](v ...func(T) bool) func(T) bool
- func Sanitizers[T any](s ...func(*T)) func(*T)
- type BuildFilterFuncOf
- type FilterFunc
- type RulerFuncOf
- func NewMapRule[K comparable, V any, M ~map[K]V](v func(V) bool, msg localeutil.LocaleStringer) RulerFuncOf[M]
- func NewMapRules[K comparable, V any, M ~map[K]V](r ...RulerFuncOf[V]) RulerFuncOf[M]
- func NewRule[T any](v func(T) bool, msg localeutil.LocaleStringer) RulerFuncOf[T]
- func NewRules[T any](r ...RulerFuncOf[T]) RulerFuncOf[T]
- func NewSliceRule[T any, S ~[]T](v func(T) bool, msg localeutil.LocaleStringer) RulerFuncOf[S]
- func NewSliceRules[T any, S ~[]T](r ...RulerFuncOf[T]) RulerFuncOf[S]
- type SanitizeFuncOf
- type ValidatorFuncOf
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Sanitizers ¶
func Sanitizers[T any](s ...func(*T)) func(*T)
Types ¶
type BuildFilterFuncOf ¶ added in v0.74.0
type BuildFilterFuncOf[T any] func(name string, v *T) FilterFunc
BuildFilterFuncOf 生成 FilterFunc 方法
name 字段名,对于切片等类型会返回带下标的字段名; v 必须是指针类型,否则 sanitize 无法对其内容进行修改;
提供此方法,主要是为了将泛型转换非泛型方法。
func New ¶
func New[T any](rule RulerFuncOf[T], sanitize ...func(*T)) BuildFilterFuncOf[T]
New 声明 FilterFunc 生成方法
sanitize 表示对字断 v 的一些清理,比如去除空白字符等,如果指定了此参数,会在 rule 之前执行;
type FilterFunc ¶
type FilterFunc func() (string, localeutil.LocaleStringer)
FilterFunc 过滤器处理函数
如果符合要求返回 "", nil,否则返回错误的字段和信息。
type RulerFuncOf ¶
type RulerFuncOf[T any] func(string, T) (string, localeutil.LocaleStringer)
RulerFuncOf 数据验证规则
这是验证器与错误信息的组合。
传递参数为字段名与需要验证的值; 返回字段名和错误信息,如果验证成功,则返回两个空值;
func NewMapRule ¶
func NewMapRule[K comparable, V any, M ~map[K]V](v func(V) bool, msg localeutil.LocaleStringer) RulerFuncOf[M]
NewMapRule 声明用于验证 map 元素的规则
func NewMapRules ¶
func NewMapRules[K comparable, V any, M ~map[K]V](r ...RulerFuncOf[V]) RulerFuncOf[M]
func NewRule ¶
func NewRule[T any](v func(T) bool, msg localeutil.LocaleStringer) RulerFuncOf[T]
func NewRules ¶
func NewRules[T any](r ...RulerFuncOf[T]) RulerFuncOf[T]
NewRules 将多个规则合并为一个
按顺序依次验证,直接碰到第一个验证不过的。
func NewSliceRule ¶
func NewSliceRule[T any, S ~[]T](v func(T) bool, msg localeutil.LocaleStringer) RulerFuncOf[S]
NewSliceRule 声明用于验证切片元素的规则
func NewSliceRules ¶
func NewSliceRules[T any, S ~[]T](r ...RulerFuncOf[T]) RulerFuncOf[S]
type SanitizeFuncOf ¶
type SanitizeFuncOf[T any] func(*T)
SanitizeFuncOf 数据修正的函数原型
实现方直接修改传递进来的参数即可。
Click to show internal directories.
Click to hide internal directories.