forked from gookit/validate
/
cache.go
53 lines (42 loc) · 878 Bytes
/
cache.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package validate
import (
"database/sql/driver"
"fmt"
)
/*
// TODO: idea for optimize ...
// - use pool for Validation
// - cache struct reflect value
// Usage:
// // use a single instance of Validate, it caches struct info
// vf := validate.NewFactory()
// v := vf.New(data)
// v.Validate()
// global factory for create Validation
var gf = newFactory()
// factory for create Validation instances
type factory struct {
// pool for Validation instances
pool sync.Pool
// m atomic.Value // map[reflect.Type]*cStruct
}
func newFactory() *factory {
f := &factory{}
f.pool.New = func() interface{} {
return newValidation(nil)
}
return f
}
func (f *factory) get() *Validation {
v := f.pool.Get().(*Validation)
// TODO clear something
return v
}
func (f *factory) put(v *Validation) {
f.pool.Put(v)
}
*/
func test() {
i32 := driver.Int32
fmt.Println(i32)
}