-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify.go
37 lines (33 loc) · 897 Bytes
/
verify.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
// Package verify provides chainable methods for easy string validation for
// common tasks
package verify
type verifier struct {
Query string
Results map[string][]bool
}
// verification initializer
func Verify(s string) *verifier {
v := &verifier{Query: s, Results: make(map[string][]bool)}
return v
}
// helper for creating a new result key or appending to an existing result slice
func (v *verifier) addVerification(key string, result bool) *verifier {
if _, ok := v.Results[key]; ok {
v.Results[key] = append(v.Results[key], result)
} else {
v.Results[key] = []bool{result}
}
return v
}
// a convenient finalizing function which confirms that all previously chained
// methods passed their verifications
func (v *verifier) IsVerified() bool {
for _, result := range v.Results {
for _, isValid := range result {
if !isValid {
return false
}
}
}
return true
}