forked from sprungknoedl/minions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
40 lines (32 loc) · 1.05 KB
/
types.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
package minions
import (
"encoding/json"
)
// BindingResult holds validation errors of the binding process from a HTML
// form to a Go struct.
type BindingResult map[string]string
// Valid returns whether the binding was successful or not.
func (br BindingResult) Valid() bool {
return len(br) == 0
}
// Fail marks the binding as failed and stores an error for the given field
// that caused the form binding to fail.
func (br BindingResult) Fail(field, err string) {
br[field] = err
}
// Include copies all errors and state of a binding result
func (br BindingResult) Include(other BindingResult) {
for field, err := range other {
br.Fail(field, err)
}
}
// MarshalJSON implements the json.Marshaler interface.
func (br BindingResult) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]string(br))
}
// V is a helper type to quickly build variable maps for templates.
type V map[string]interface{}
// MarshalJSON implements the json.Marshaler interface.
func (v V) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}(v))
}