本文整理汇总了Golang中github.com/cloudwan/gohan/schema.Schema.HandleUpdate方法的典型用法代码示例。如果您正苦于以下问题:Golang Schema.HandleUpdate方法的具体用法?Golang Schema.HandleUpdate怎么用?Golang Schema.HandleUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudwan/gohan/schema.Schema
的用法示例。
在下文中一共展示了Schema.HandleUpdate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UpdateResourceInTransaction
// UpdateResourceInTransaction updates resource in db in transaction
func UpdateResourceInTransaction(
context middleware.Context,
resourceSchema *schema.Schema, resourceID string,
dataMap map[string]interface{}, tenantIDs []string) error {
manager := schema.GetManager()
mainTransaction := context["transaction"].(transaction.Transaction)
environmentManager := extension.GetManager()
environment, ok := environmentManager.GetEnvironment(resourceSchema.ID)
if !ok {
return fmt.Errorf("No environment for schema")
}
resource, err := mainTransaction.Fetch(
resourceSchema, resourceID, tenantIDs)
if err != nil {
return ResourceError{err, err.Error(), WrongQuery}
}
err = resource.Update(dataMap)
if err != nil {
return ResourceError{err, err.Error(), WrongData}
}
context["resource"] = resource.Data()
if err := handleEvent(context, environment, "pre_update_in_transaction"); err != nil {
return err
}
dataMap, ok = context["resource"].(map[string]interface{})
if !ok {
return fmt.Errorf("Resource not JSON: %s", err)
}
resource, err = manager.LoadResource(resourceSchema.ID, dataMap)
if err != nil {
return fmt.Errorf("Loading Resource failed: %s", err)
}
err = mainTransaction.Update(resource)
if err != nil {
return ResourceError{err, fmt.Sprintf("Failed to store data in database: %v", err), UpdateFailed}
}
resourceSchema.HandleUpdate(resource)
response := map[string]interface{}{}
response[resourceSchema.Singular] = resource.Data()
context["response"] = response
if err := handleEvent(context, environment, "post_update_in_transaction"); err != nil {
return err
}
return nil
}