-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinternal.go
73 lines (63 loc) · 1.78 KB
/
internal.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package crud
import (
"fmt"
)
// initHelpers creates all the Struct2sql objects. For HTTP endpoints, it is necessary to create these first
func (c *Controller) initHelpers(newObjFunc func() interface{}, options HandlerOptions) error {
obj := newObjFunc()
var forceName string
if options.ForceName != "" {
forceName = options.ForceName
}
cErr := c.orm.RegisterStruct(obj, nil, false, forceName, false)
if cErr != nil {
return ErrController{
Op: "RegisterStruct",
Err: fmt.Errorf("Error adding SQL generator: %s", cErr.Error()),
}
}
if options.CreateConstructor != nil {
cErr = c.orm.RegisterStruct(options.CreateConstructor(), obj, false, "", true)
if cErr != nil {
return ErrController{
Op: "RegisterStruct",
Err: fmt.Errorf("Error adding SQL generator: %s", cErr.Error()),
}
}
}
if options.ReadConstructor != nil {
cErr = c.orm.RegisterStruct(options.ReadConstructor(), obj, false, "", true)
if cErr != nil {
return ErrController{
Op: "RegisterStruct",
Err: fmt.Errorf("Error adding SQL generator: %s", cErr.Error()),
}
}
}
if options.UpdateConstructor != nil {
cErr = c.orm.RegisterStruct(options.UpdateConstructor(), obj, false, "", true)
if cErr != nil {
return ErrController{
Op: "RegisterStruct",
Err: fmt.Errorf("Error adding SQL generator: %s", cErr.Error()),
}
}
}
if options.ListConstructor != nil {
cErr = c.orm.RegisterStruct(options.ListConstructor(), obj, false, "", true)
if cErr != nil {
return ErrController{
Op: "RegisterStruct",
Err: fmt.Errorf("Error adding SQL generator: %s", cErr.Error()),
}
}
}
return nil
}
func (c Controller) mapWithInterfacesToMapBool(m map[string]interface{}) map[string]bool {
o := map[string]bool{}
for k := range m {
o[k] = true
}
return o
}