31 lines
684 B
Go
31 lines
684 B
Go
package validator
|
|
|
|
var defaultNotifValidator *NotifValidator
|
|
|
|
type NotifValidateFunc func(...any) (bool, error)
|
|
|
|
type NotifValidator struct {
|
|
validators map[int64]NotifValidateFunc
|
|
}
|
|
|
|
func InitDefaultNotifValidator() {
|
|
defaultNotifValidator = new(NotifValidator)
|
|
defaultNotifValidator.init()
|
|
}
|
|
|
|
func GetDefaultNotifValidator() *NotifValidator {
|
|
return defaultNotifValidator
|
|
}
|
|
|
|
func (p *NotifValidator) init() {
|
|
p.validators = make(map[int64]NotifValidateFunc)
|
|
}
|
|
|
|
func (p *NotifValidator) Validate(id int64, params ...any) (bool, error) {
|
|
return p.validators[id](params...)
|
|
}
|
|
|
|
func (p *NotifValidator) RegValidateFunc(id int64, fun NotifValidateFunc) {
|
|
p.validators[id] = fun
|
|
}
|