|
@@ -11,7 +11,8 @@ import (
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
- getFns map[string]func(args map[string]string) (interface{}, error)
|
|
|
+ getFns map[string]func(args map[string]string) (interface{}, error)
|
|
|
+ postFns map[string]func(args map[string]string, r *http.Request) (interface{}, error)
|
|
|
)
|
|
|
|
|
|
func init() {
|
|
@@ -20,7 +21,9 @@ func init() {
|
|
|
|
|
|
func MapModels(models []interface{}, handlers map[string]string) {
|
|
|
for _, model := range models {
|
|
|
+
|
|
|
name := inflection.Plural(strings.ToLower(modelName(model)))
|
|
|
+
|
|
|
for p, action := range map[string]string{
|
|
|
"": "GetAll",
|
|
|
"create": "Create",
|
|
@@ -29,6 +32,13 @@ func MapModels(models []interface{}, handlers map[string]string) {
|
|
|
} {
|
|
|
getFns[path.Join("/", name, p)] = reflect.ValueOf(model).MethodByName(action).Interface().(func(map[string]string) (interface{}, error))
|
|
|
}
|
|
|
+
|
|
|
+ for p, action := range map[string]string{
|
|
|
+ "{id}/udpate": "Update",
|
|
|
+ } {
|
|
|
+ getFns[path.Join("/", name, p)] = reflect.ValueOf(model).MethodByName(action).Interface().(func(map[string]string) (interface{}, error))
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|