1
0
mirror of https://github.com/rancher/norman.git synced 2025-04-28 11:24:47 +00:00
norman/api/handler/update.go
2018-02-14 10:59:23 -07:00

29 lines
587 B
Go

package handler
import (
"net/http"
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
)
func UpdateHandler(apiContext *types.APIContext, next types.RequestHandler) error {
data, err := ParseAndValidateBody(apiContext, false)
if err != nil {
return err
}
store := apiContext.Schema.Store
if store == nil {
return httperror.NewAPIError(httperror.NotFound, "no store found")
}
data, err = store.Update(apiContext, apiContext.Schema, data, apiContext.ID)
if err != nil {
return err
}
apiContext.WriteResponse(http.StatusOK, data)
return nil
}