-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator.go
More file actions
37 lines (28 loc) · 825 Bytes
/
validator.go
File metadata and controls
37 lines (28 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* Copyright (c) 2024-2026 Mikhail Knyazhev <markus621@yandex.com>. All rights reserved.
* Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
*/
package validate
import "context"
type Validator struct {
store *store
structVld *structValidator
}
func New() *Validator {
return &Validator{
store: newStore(),
structVld: newStructValidator(),
}
}
func (v *Validator) Register(rules ...Rule) error {
return v.store.Append(rules...)
}
func (v *Validator) ValidateStruct(ctx context.Context, arg any) error {
return v.structVld.run(ctx, v.store, arg)
}
func (v *Validator) Validate(ctx context.Context, call func(c Callback)) error {
cb := poolCallbackValidator.Get()
defer poolCallbackValidator.Put(cb)
call(cb)
return cb.run(ctx, v.store)
}