-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunc_types.go
More file actions
38 lines (31 loc) · 1.25 KB
/
func_types.go
File metadata and controls
38 lines (31 loc) · 1.25 KB
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
package forms
//ValidatorFunc is a function that conforms to the Validator interface. Similar
//to the http.Handler/http.HandlerFunc in net/http
type ValidatorFunc func(string) (string, error)
//Validate implements the Validator interface for ValidatorFunc
func (v ValidatorFunc) Validate(in string) (out string, err error) {
out, err = v(in)
return
}
//ConverterFunc is a function that conforms to the Converter interface. Similar
//to the http.Handler/http.HandlerFunc in net/http
type ConverterFunc func(string) (interface{}, error)
//Convert implements the Converter interface for ConverterFunc
func (c ConverterFunc) Convert(in string) (out interface{}, err error) {
out, err = c(in)
return
}
//LoaderFunc is a function that conforms to the Loader interface. Similar
//to the http.Handler/http.HandlerFunc in net/http
type LoaderFunc func(map[string]interface{}) (interface{}, map[string]error, error)
//Load implements the Loader interface for LoaderFunc
func (l LoaderFunc) Load(in map[string]interface{}) (out interface{}, errs map[string]error, err error) {
out, errs, err = l(in)
return
}
//Assert that our Funcs are of the correct interface type
var (
_ Loader = LoaderFunc(nil)
_ Converter = ConverterFunc(nil)
_ Validator = ValidatorFunc(nil)
)