Skip to content

Commit 1595a4e

Browse files
committed
reduce template code
1 parent e45e2e4 commit 1595a4e

File tree

7 files changed

+45
-90
lines changed

7 files changed

+45
-90
lines changed

internal/common/autogen/handle_operations.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ type HandleCreateReq struct {
4949

5050
func HandleCreate(ctx context.Context, req HandleCreateReq) {
5151
d := &req.Resp.Diagnostics
52+
if d.HasError() {
53+
return
54+
}
5255
bodyReq, err := Marshal(req.Plan, false)
5356
if err != nil {
5457
addError(d, opCreate, errBuildingAPIRequest, err)
@@ -117,6 +120,9 @@ type HandleUpdateReq struct {
117120

118121
func HandleUpdate(ctx context.Context, req HandleUpdateReq) {
119122
d := &req.Resp.Diagnostics
123+
if d.HasError() {
124+
return
125+
}
120126
bodyReq, err := Marshal(req.Plan, true)
121127
if err != nil {
122128
addError(d, opUpdate, errBuildingAPIRequest, err)
@@ -155,6 +161,9 @@ type HandleDeleteReq struct {
155161

156162
func HandleDelete(ctx context.Context, req HandleDeleteReq) {
157163
d := &req.Resp.Diagnostics
164+
if d.HasError() {
165+
return
166+
}
158167
var err error
159168
if req.StaticRequestBody == "" {
160169
_, _, err = callAPIWithoutBody(ctx, req.Client, req.CallParams)

internal/serviceapi/clusterapi/resource.go

Lines changed: 6 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/serviceapi/pushbasedlogexportapi/resource.go

Lines changed: 6 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/serviceapi/searchdeploymentapi/resource.go

Lines changed: 6 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/serviceapi/streamprocessorapi/resource.go

Lines changed: 6 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/codegen/gofilegen/codetemplate/resource-file.go.tmpl

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,8 @@ func (r *rs) Create(ctx context.Context, req resource.CreateRequest, resp *resou
5353
Method: "{{ .APIOperations.Create.HTTPMethod }}",
5454
}
5555
{{with .APIOperations.Create.Wait -}}
56-
timeout, diags := plan.Timeouts.Create(ctx, {{ .TimeoutSeconds }}*time.Second)
57-
resp.Diagnostics.Append(diags...)
58-
if resp.Diagnostics.HasError() {
59-
return
60-
}
56+
timeout, localDiags := plan.Timeouts.Create(ctx, {{ .TimeoutSeconds }}*time.Second)
57+
resp.Diagnostics.Append(localDiags...)
6158
{{ end -}}
6259
reqHandle := autogen.HandleCreateReq {
6360
Resp: resp,
@@ -114,11 +111,8 @@ func (r *rs) Update(ctx context.Context, req resource.UpdateRequest, resp *resou
114111
Method: "{{ .APIOperations.Update.HTTPMethod }}",
115112
}
116113
{{with .APIOperations.Update.Wait -}}
117-
timeout, diags := plan.Timeouts.Update(ctx, {{ .TimeoutSeconds }}*time.Second)
118-
resp.Diagnostics.Append(diags...)
119-
if resp.Diagnostics.HasError() {
120-
return
121-
}
114+
timeout, localDiags := plan.Timeouts.Update(ctx, {{ .TimeoutSeconds }}*time.Second)
115+
resp.Diagnostics.Append(localDiags...)
122116
{{ end -}}
123117
reqHandle := autogen.HandleUpdateReq {
124118
Resp: resp,
@@ -158,11 +152,8 @@ func (r *rs) Delete(ctx context.Context, req resource.DeleteRequest, resp *resou
158152
Method: "{{ .APIOperations.Delete.HTTPMethod }}",
159153
}
160154
{{with .APIOperations.Delete.Wait -}}
161-
timeout, diags := state.Timeouts.Delete(ctx, {{ .TimeoutSeconds }}*time.Second)
162-
resp.Diagnostics.Append(diags...)
163-
if resp.Diagnostics.HasError() {
164-
return
165-
}
155+
timeout, localDiags := state.Timeouts.Delete(ctx, {{ .TimeoutSeconds }}*time.Second)
156+
resp.Diagnostics.Append(localDiags...)
166157
{{ end -}}
167158
reqHandle := autogen.HandleDeleteReq {
168159
Resp: resp,

tools/codegen/gofilegen/resource/testdata/wait-configuration.golden.go

Lines changed: 6 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)