fix(common): supported dry run

This commit is contained in:
Qu Xuan
2021-06-09 20:12:44 +08:00
parent 0b0ac0f151
commit 705e068a6e
2 changed files with 13 additions and 0 deletions
+4
View File
@@ -183,6 +183,10 @@ type StandaloneAnonResourceCreateInput struct {
// 标签列表,最多支持20个
// example: { "user:rd": "op" }
Metadata map[string]string `json:"__meta__" token:"tag" help:"tags in the form of key=value"`
// 预检验参数,若为true则仅检查参数,并不真正创建变更
// default: false
DryRun bool `json:"dry_run"`
}
type StandaloneResourceCreateInput struct {
+9
View File
@@ -1269,6 +1269,15 @@ func _doCreateItem(
if err != nil {
return nil, httperrors.NewGeneralError(err)
}
dryRun := struct {
DryRun bool
}{}
data.Unmarshal(&dryRun)
if dryRun.DryRun {
return model, nil
}
err = manager.TableSpec().InsertOrUpdate(ctx, model)
if err != nil {
return nil, httperrors.NewGeneralError(err)