Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let err returned by ReadBody more readable #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions network/http/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,12 @@ func GinGetArg(c *gin.Context, hdr, param string) (v string, err error) {
func Unzip(in []byte) (out []byte, err error) {
gzr, err := gzip.NewReader(bytes.NewBuffer(in))
if err != nil {
return
return nil, fmt.Errorf("unable to new gzip reader: %w", err)
}

out, err = io.ReadAll(gzr)
if err != nil {
return
return out, fmt.Errorf("unable to ReadAll from gzip reader: %w", err)
}

if err := gzr.Close(); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion network/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package http

import (
"fmt"
"io"
"net/http"
)
Expand All @@ -15,7 +16,7 @@ import (
func ReadBody(req *http.Request) ([]byte, error) {
buf, err := io.ReadAll(req.Body)
if err != nil {
return nil, err
return nil, fmt.Errorf("io ReadAll in ReadBody: %w", err)
}

// as HTTP server, we do not need to close body
Expand Down