Skip to content

Commit

Permalink
upgrade dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
suzhen committed Mar 20, 2021
1 parent d9d7e7d commit 5676563
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/guestin/go-duface
go 1.16

require (
github.com/guestin/go-requests v0.0.8
github.com/guestin/go-requests v0.0.9
github.com/guestin/mob v1.0.7
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/guestin/go-requests v0.0.8 h1:TKdROouom+nVPdBXIsn4IUXWRWpUMkF570/fL9itWg0=
github.com/guestin/go-requests v0.0.8/go.mod h1:gB+JWM1CotK0tHuHu0DpMTmp7TmeXrxgHTx4IAEl+9c=
github.com/guestin/go-requests v0.0.9 h1:udMlhGrinOVA0synB2PGI5p1zGJs02LNBttqkgeEGTk=
github.com/guestin/go-requests v0.0.9/go.mod h1:gB+JWM1CotK0tHuHu0DpMTmp7TmeXrxgHTx4IAEl+9c=
github.com/guestin/mob v1.0.7 h1:EOtNE9L+OYcxkVDGvYGzTHid8W0lXeMFInlZm//JBqM=
github.com/guestin/mob v1.0.7/go.mod h1:rIQZ+ImMfZM8E3wyP4mpS8Ux9T92198XtQMFT/l6enI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down
34 changes: 16 additions & 18 deletions internal/opt_dump_response.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
package internal

import (
"bytes"
"fmt"
"github.com/guestin/go-requests/opt"
"io"
)

func DumpResponse(tag string) opt.Option {
return func(context *opt.RequestContext) error {
old := context.ResponseHandler
context.ResponseHandler = func(statusCode int, stream io.Reader) (interface{}, error) {
fmt.Printf("[%s] status code=%d\n", tag, statusCode)
respBytes, err := io.ReadAll(stream)
if err != nil {
fmt.Printf("[%s] read response error:%s\n", tag, err)
return nil, err
}
fmt.Printf("[%s] response:%s\n", tag, respBytes)
if old != nil {
return old(statusCode, bytes.NewReader(respBytes))
}
return nil, nil
}
func DumpResponse(tag string, skip bool) opt.Option {
return func(reqCtx *opt.RequestContext) error {
reqCtx.InstallResponseHandler(
func(statusCode int, stream io.Reader, previousValue interface{}) (interface{}, error) {
if skip {
return previousValue, nil
}
fmt.Printf("[%s] status code=%d\n", tag, statusCode)
respBytes, err := io.ReadAll(stream)
if err != nil {
fmt.Printf("[%s] read response error:%s\n", tag, err)
return nil, err
}
fmt.Printf("[%s] response:%s\n", tag, respBytes)
return nil, nil
}, opt.HEAD)
return nil
}

}

0 comments on commit 5676563

Please sign in to comment.