forked from mtusi2026/mtusi2026lab6
Реализация на 5
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
type TagKey string
|
||||
|
||||
type ValidatorImpl struct {
|
||||
validator *validator.Validate
|
||||
}
|
||||
|
||||
func NewValidatorImpl() *ValidatorImpl {
|
||||
return &ValidatorImpl{validator: validator.New()}
|
||||
}
|
||||
|
||||
func (v *ValidatorImpl) Register(tag TagKey, fn validator.Func, callValidationEvenIfNull ...bool) error {
|
||||
return v.validator.RegisterValidation(string(tag), fn, callValidationEvenIfNull...)
|
||||
}
|
||||
|
||||
func (v *ValidatorImpl) ValidateCtx(ctx context.Context, value any) error {
|
||||
return v.validator.StructCtx(ctx, value)
|
||||
}
|
||||
|
||||
func (v *ValidatorImpl) Validate(value any) error {
|
||||
return v.validator.Struct(value)
|
||||
}
|
||||
Reference in New Issue
Block a user