mirror of
https://github.com/rancher/norman.git
synced 2025-09-26 23:25:13 +00:00
More initial dev
This commit is contained in:
31
api/handlers/create.go
Normal file
31
api/handlers/create.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/rancher/norman/types"
|
||||
)
|
||||
|
||||
func CreateHandler(request *types.APIContext) error {
|
||||
var err error
|
||||
|
||||
validator := request.Schema.Validator
|
||||
if validator != nil {
|
||||
if err := validator(request, request.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
data := request.Body
|
||||
|
||||
store := request.Schema.Store
|
||||
if store != nil {
|
||||
data, err = store.Create(request, request.Schema, data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
request.WriteResponse(http.StatusCreated, data)
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user