-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuncs.go
47 lines (39 loc) · 1.25 KB
/
funcs.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
package golidera
func Check(g GolideraFielder, fi Fielder, f Former, checks []Checker, l ...string) (bool, error) {
for _, check := range checks {
passes, err := check.Check(g, fi, f, l...)
if !passes {
return false, err
}
}
return true, nil
}
func CheckAll(g GolideraFielder, fi Fielder, f Former, checks []Checker, l ...string) (bool, []error) {
var errors []error
valid := true
for _, check := range checks {
passes, err := check.Check(g, fi, f, l...)
if !passes {
valid = false
errors = append(errors, err)
}
}
if valid {
return true, nil
}
return false, errors
}
type Checker interface {
Check(GolideraFielder, Fielder, Former, ...string) (bool, error)
}
type CheckerFunc func(GolideraFielder, Fielder, Former, ...string) (bool, error)
func (this CheckerFunc) Check(g GolideraFielder, fi Fielder, f Former, t ...string) (bool, error) {
return this(g, fi, f, t...)
}
type Conditioner interface {
Assert(GolideraFielder, Fielder, Former, bool, ...string) (bool, []error)
}
type ConditionerFunc func(GolideraFielder, Fielder, Former, bool, ...string) (bool, []error)
func (this ConditionerFunc) Assert(g GolideraFielder, fi Fielder, f Former, firstOnly bool, l ...string) (bool, []error) {
return this(g, fi, f, firstOnly, l...)
}