Skip to content

Commit

Permalink
Simplify decode request body function removing ReadAll method
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo Reis committed Sep 29, 2023
1 parent a51a607 commit bfeb946
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions handler.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package bigqueryudf

import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"

"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -61,13 +59,9 @@ func decodeRequestBody(r *http.Request, request any) error {
defer func() {
_ = r.Body.Close()
}()
body, err := io.ReadAll(r.Body)
if err != nil {
return fmt.Errorf("reading http request body: %w", err)
}
dec := json.NewDecoder(bytes.NewReader(body))
dec := json.NewDecoder(r.Body)
dec.DisallowUnknownFields()
err = dec.Decode(&request)
err := dec.Decode(&request)
if err != nil {
return fmt.Errorf("decoding http request body: %w", err)

Expand Down

0 comments on commit bfeb946

Please sign in to comment.