本文整理汇总了Golang中github.com/cloudwan/gohan/schema.Schema.Validate方法的典型用法代码示例。如果您正苦于以下问题:Golang Schema.Validate方法的具体用法?Golang Schema.Validate怎么用?Golang Schema.Validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudwan/gohan/schema.Schema
的用法示例。
在下文中一共展示了Schema.Validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ActionResource
// ActionResource runs custom action on resource
func ActionResource(context middleware.Context, dataStore db.DB, identityService middleware.IdentityService,
resourceSchema *schema.Schema, action schema.Action, resourceID string, data interface{},
) error {
actionSchema := action.InputSchema
context["input"] = data
context["id"] = resourceID
environmentManager := extension.GetManager()
environment, ok := environmentManager.GetEnvironment(resourceSchema.ID)
if !ok {
return fmt.Errorf("No environment for schema")
}
if actionSchema != nil {
err := resourceSchema.Validate(actionSchema, data)
if err != nil {
return ResourceError{err, fmt.Sprintf("Validation error: %s", err), WrongData}
}
}
err := extension.HandleEvent(context, environment, action.ID)
if err != nil {
return err
}
if _, ok := context["response"]; ok {
return nil
}
return fmt.Errorf("no response")
}
示例2: ActionResource
// ActionResource runs custom action on resource
func ActionResource(context middleware.Context, dataStore db.DB, identityService middleware.IdentityService,
resourceSchema *schema.Schema, action schema.Action, resourceID string, data interface{},
) error {
actionSchema := action.InputSchema
context["input"] = data
context["id"] = resourceID
environmentManager := extension.GetManager()
environment, ok := environmentManager.GetEnvironment(resourceSchema.ID)
if !ok {
return fmt.Errorf("No environment for schema")
}
err := resourceSchema.Validate(actionSchema, data)
if err != nil {
return ResourceError{err, fmt.Sprintf("Validation error: %s", err), WrongData}
}
if err := handleEvent(context, environment, fmt.Sprintf("pre_%s", action.ID)); err != nil {
return err
}
if err := InTransaction(context, dataStore, func() error {
return handleEvent(context, environment, fmt.Sprintf("pre_%s_in_transaction", action.ID))
}); err != nil {
return err
}
if err := handleEvent(context, environment, action.ID); err != nil {
return err
}
if err := InTransaction(context, dataStore, func() error {
return handleEvent(context, environment, fmt.Sprintf("post_%s_in_transaction", action.ID))
}); err != nil {
return err
}
if err := handleEvent(context, environment, fmt.Sprintf("post_%s", action.ID)); err != nil {
return err
}
if rawResponse, ok := context["response"]; ok {
if _, ok := rawResponse.(map[string]interface{}); ok {
return nil
}
return fmt.Errorf("extension returned invalid JSON: %v", rawResponse)
}
return fmt.Errorf("no response")
}