1
0
mirror of https://github.com/rancher/norman.git synced 2025-05-09 16:47:05 +00:00

Add Create to access

This commit is contained in:
Darren Shepherd 2018-04-19 21:55:54 -07:00
parent e2757753e1
commit 0e1438b372

View File

@ -8,6 +8,32 @@ import (
"github.com/rancher/norman/types/convert"
)
func Create(context *types.APIContext, version *types.APIVersion, typeName string, data map[string]interface{}, into interface{}) error {
schema := context.Schemas.Schema(version, typeName)
if schema == nil {
return fmt.Errorf("failed to find schema " + typeName)
}
item, err := schema.Store.Create(context, schema, data)
if err != nil {
return err
}
b := builder.NewBuilder(context)
b.Version = version
item, err = b.Construct(schema, item, builder.List)
if err != nil {
return err
}
if into == nil {
return nil
}
return convert.ToObj(item, into)
}
func ByID(context *types.APIContext, version *types.APIVersion, typeName string, id string, into interface{}) error {
schema := context.Schemas.Schema(version, typeName)
if schema == nil {