Skip to content

Commit

Permalink
Remove unnecessary defer call
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechVitek committed Dec 10, 2023
1 parent eafad80 commit 7545fd7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions client.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,12 @@ func (c *{{$serviceNameClient}}) {{$method.Name}}(ctx context.Context{{range $_,
{{- end }}

resp, err := doHTTPRequest(ctx, c.client, c.urls[{{$i}}], {{$inputVar}}, {{$outputVar}})
defer func() {
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
if resp != nil {
cerr := resp.Body.Close()
if err == nil && cerr != nil {
err = ErrWebrpcRequestFailed.WithCause(fmt.Errorf("failed to close response body: %w", cerr))
}
}()
}

return {{range $i, $output := $method.Outputs}}out.Ret{{$i}}, {{end}}err
}
Expand Down
2 changes: 1 addition & 1 deletion types.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (w *{{firstLetterToLower $method.Name}}StreamWriter) Write({{range $i, $out

{{ end }}
{{- end }}
{{ end }}
{{- end }}

{{- if $opts.streaming -}}

Expand Down

0 comments on commit 7545fd7

Please sign in to comment.