Files
k3s/vendor/github.com/rancher/norman/api/handler/create.go
Darren Shepherd fa08d6076c Update vendor
2019-01-11 21:58:27 -07:00

31 lines
592 B
Go

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