1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-25 06:26:50 +00:00

Many enhancements

This commit is contained in:
Darren Shepherd
2017-12-11 20:58:43 -07:00
parent eef2c6ee6e
commit 406c0d9999
12 changed files with 63 additions and 47 deletions

View File

@@ -9,7 +9,7 @@ import (
func CreateHandler(apiContext *types.APIContext) error {
var err error
data, err := ParseAndValidateBody(apiContext)
data, err := ParseAndValidateBody(apiContext, true)
if err != nil {
return err
}

View File

@@ -7,7 +7,7 @@ import (
)
func UpdateHandler(apiContext *types.APIContext) error {
data, err := ParseAndValidateBody(apiContext)
data, err := ParseAndValidateBody(apiContext, false)
if err != nil {
return err
}

View File

@@ -6,7 +6,7 @@ import (
"github.com/rancher/norman/types"
)
func ParseAndValidateBody(apiContext *types.APIContext) (map[string]interface{}, error) {
func ParseAndValidateBody(apiContext *types.APIContext, create bool) (map[string]interface{}, error) {
data, err := parse.Body(apiContext.Request)
if err != nil {
return nil, err
@@ -14,7 +14,11 @@ func ParseAndValidateBody(apiContext *types.APIContext) (map[string]interface{},
b := builder.NewBuilder(apiContext)
data, err = b.Construct(apiContext.Schema, data, builder.Create)
op := builder.Create
if !create {
op = builder.Update
}
data, err = b.Construct(apiContext.Schema, data, op)
if err != nil {
return nil, err
}