24 lines
410 B
Go
24 lines
410 B
Go
package grequests
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
// Response 封装 HTTP 响应
|
|
type Response struct {
|
|
StatusCode int
|
|
Body []byte
|
|
Headers http.Header
|
|
}
|
|
|
|
// Text 返回响应的文本内容
|
|
func (r *Response) Text() string {
|
|
return string(r.Body)
|
|
}
|
|
|
|
// JSON 解析响应为 JSON 并存储到指定变量
|
|
func (r *Response) JSON(v interface{}) error {
|
|
return json.Unmarshal(r.Body, v)
|
|
}
|