mirror of
https://github.com/rancher/norman.git
synced 2025-06-22 13:37:17 +00:00
Add Create to access
This commit is contained in:
parent
e2757753e1
commit
0e1438b372
@ -8,6 +8,32 @@ import (
|
|||||||
"github.com/rancher/norman/types/convert"
|
"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 {
|
func ByID(context *types.APIContext, version *types.APIVersion, typeName string, id string, into interface{}) error {
|
||||||
schema := context.Schemas.Schema(version, typeName)
|
schema := context.Schemas.Schema(version, typeName)
|
||||||
if schema == nil {
|
if schema == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user