File tree 1 file changed +12
-13
lines changed
1 file changed +12
-13
lines changed Original file line number Diff line number Diff line change 1
1
package hasaki
2
2
3
3
import (
4
+ "errors"
4
5
"github.com/json-iterator/go"
5
6
"io/ioutil"
6
7
"net/http"
@@ -16,30 +17,28 @@ func (c *Response) Err() error {
16
17
}
17
18
18
19
func (c * Response ) GetBody () ([]byte , error ) {
19
- defer func () {
20
- if c .Body != nil {
21
- c .Body .Close ()
22
- }
23
- }()
24
20
if c .err != nil {
25
21
return nil , c .err
26
22
}
23
+ if c .Response == nil {
24
+ return nil , errors .New ("response is nil" )
25
+ }
26
+ defer c .Body .Close ()
27
27
return ioutil .ReadAll (c .Body )
28
28
}
29
29
30
30
func (c * Response ) BindJSON (v interface {}) error {
31
- defer func () {
32
- if c .Body != nil {
33
- c .Body .Close ()
34
- }
35
- }()
36
-
37
31
if c .err != nil {
38
32
return c .err
39
33
}
40
- body , err := ioutil .ReadAll (c .Body )
34
+ if c .Response == nil {
35
+ return errors .New ("response is nil" )
36
+ }
37
+ defer c .Body .Close ()
38
+
39
+ content , err := ioutil .ReadAll (c .Body )
41
40
if err != nil {
42
41
return err
43
42
}
44
- return jsoniter .Unmarshal (body , v )
43
+ return jsoniter .Unmarshal (content , v )
45
44
}
You can’t perform that action at this time.
0 commit comments