Skip to content

Commit

Permalink
fix: use io.ReadAll
Browse files Browse the repository at this point in the history
  • Loading branch information
burkedavison committed Jul 2, 2024
1 parent f0e32bc commit c3f335d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions util/genrest/goviewcreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func NewView(model *gomodel.Model) (*goview.View, error) {
source.P(" // Intentional: Field values in the URL path override those set in the body.")
source.P(" var jsonReader bytes.Buffer")
source.P(" bodyReader := io.TeeReader(r.Body, &jsonReader)")
source.P(" rBytes := make([]byte, r.ContentLength)")
source.P(" if _, err := bodyReader.Read(rBytes); err != nil && err != io.EOF {")
source.P(" rBytes, err := io.ReadAll(bodyReader)")
source.P(" if err != nil && err != io.EOF {")
source.P(` backend.Error(w, http.StatusBadRequest, "error reading body content: %%s", err)`)
source.P(" return")
source.P(" }")
Expand Down Expand Up @@ -154,8 +154,8 @@ func NewView(model *gomodel.Model) (*goview.View, error) {
source.P(" var %s %s.%s", handler.RequestBodyFieldVariable, handler.RequestBodyFieldPackage, handler.RequestBodyFieldType)
source.P(" var jsonReader bytes.Buffer")
source.P(" bodyReader := io.TeeReader(r.Body, &jsonReader)")
source.P(" rBytes := make([]byte, r.ContentLength)")
source.P(" if _, err := bodyReader.Read(rBytes); err != nil && err != io.EOF {")
source.P(" rBytes, err := io.ReadAll(bodyReader)")
source.P(" if err != nil && err != io.EOF {")
source.P(` backend.Error(w, http.StatusBadRequest, "error reading body content: %%s", err)`)
source.P(" return")
source.P(" }")
Expand Down

0 comments on commit c3f335d

Please sign in to comment.