-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes_gen.go
35 lines (29 loc) · 867 Bytes
/
types_gen.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
package model
//go:generate genny -pkg="model" -in=$GOFILE -out=types.go gen "Type=BUILTINS,interface{}"
import (
"errors"
"github.com/cheekybits/genny/generic"
"github.com/cheekybits/m"
)
// Type is the generic type placeholder.
type Type generic.Type
// IsType checks to make sure the value is a Type.
// Remains silent if the data is not present.
func IsType(data map[string]interface{}, keypath string) error {
if v, ok := m.GetOK(data, keypath); ok {
if _, ok := v.(Type); !ok {
return errors.New("must be Type")
}
}
return nil
}
// IsTypeSlice checks to make sure the value is a Type.
// Remains silent if the data is not present.
func IsTypeSlice(data map[string]interface{}, keypath string) error {
if v, ok := m.GetOK(data, keypath); ok {
if _, ok := v.([]Type); !ok {
return errors.New("must be array of Type")
}
}
return nil
}