本文整理匯總了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
}