httputil

package
v1.9.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CombineHandlers

func CombineHandlers(list ...func(w http.ResponseWriter, r *http.Request) (next bool)) func(w http.ResponseWriter, r *http.Request)

合并多个http中间件,如果中间件返回true表示继续执行下一个

func GetClient

func GetClient() *http.Client

获取客户端

func SetClient

func SetClient(opts ClientOptions)

设置客户端

Types

type ClientOptions

type ClientOptions struct {
	Proxy   string
	Timeout time.Duration
	Client  *http.Client
}

type HttpRequest

type HttpRequest struct {
	Client      *http.Client
	URL         string
	Method      string
	Header      http.Header
	Query       url.Values
	RequestBody io.Reader
	Timeout     time.Duration
}

func Request

func Request() *HttpRequest

新请求

func RequestWithClient

func RequestWithClient(client *http.Client) *HttpRequest

新请求,自己设置Client实例

func (*HttpRequest) AcceptJSON

func (r *HttpRequest) AcceptJSON() *HttpRequest

期望JSON响应

func (*HttpRequest) AddHeader

func (r *HttpRequest) AddHeader(key string, value string) *HttpRequest

添加请求头

func (*HttpRequest) AddQuery

func (r *HttpRequest) AddQuery(key string, value string) *HttpRequest

添加查询参数

func (*HttpRequest) Clone

func (r *HttpRequest) Clone() *HttpRequest

复制一份请求

func (*HttpRequest) DELETE

func (r *HttpRequest) DELETE(url string) *HttpRequest

DELETE

func (*HttpRequest) GET

func (r *HttpRequest) GET(url string) *HttpRequest

GET

func (*HttpRequest) HEAD

func (r *HttpRequest) HEAD(url string) *HttpRequest

HEAD

func (*HttpRequest) MustSend

func (r *HttpRequest) MustSend() *HttpResponse

发送请求,如果出错则panic

func (*HttpRequest) OPTIONS

func (r *HttpRequest) OPTIONS(url string) *HttpRequest

OPTIONS

func (*HttpRequest) POST

func (r *HttpRequest) POST(url string) *HttpRequest

POST

func (*HttpRequest) PUT

func (r *HttpRequest) PUT(url string) *HttpRequest

PUT

func (*HttpRequest) Send

func (r *HttpRequest) Send() (*HttpResponse, error)

发送请求

func (*HttpRequest) SetHeader

func (r *HttpRequest) SetHeader(key string, value string) *HttpRequest

设置请求头

func (*HttpRequest) SetQuery

func (r *HttpRequest) SetQuery(key string, value string) *HttpRequest

设置查询参数

func (*HttpRequest) TRACE

func (r *HttpRequest) TRACE(url string) *HttpRequest

TRACE

func (*HttpRequest) WithBody added in v1.5.0

func (r *HttpRequest) WithBody(body io.Reader) *HttpRequest

设置请求体

func (*HttpRequest) WithJSONBody added in v1.5.0

func (r *HttpRequest) WithJSONBody(data interface{}) *HttpRequest

设置JSON请求体

func (*HttpRequest) WithMethod

func (r *HttpRequest) WithMethod(method string) *HttpRequest

设置请求方法

func (*HttpRequest) WithTimeout added in v1.5.0

func (r *HttpRequest) WithTimeout(d time.Duration) *HttpRequest

设置超时时间

func (*HttpRequest) WithURL

func (r *HttpRequest) WithURL(url string) *HttpRequest

设置请求地址

type HttpResponse

type HttpResponse struct {
	// contains filtered or unexported fields
}

func (*HttpResponse) Body

func (r *HttpResponse) Body() ([]byte, error)

响应体

func (*HttpResponse) Close

func (r *HttpResponse) Close() error

关闭

func (*HttpResponse) Header

func (r *HttpResponse) Header() http.Header

响应天

func (*HttpResponse) JSON

func (r *HttpResponse) JSON(data interface{}) error

JSON响应体

func (*HttpResponse) Map

func (r *HttpResponse) Map() (map[string]interface{}, error)

Map响应体

func (*HttpResponse) MustBody

func (r *HttpResponse) MustBody() []byte

响应体,如果出错则panic

func (*HttpResponse) MustMap

func (r *HttpResponse) MustMap() map[string]interface{}

Map响应体,如果出错则panic

func (*HttpResponse) Origin

func (r *HttpResponse) Origin() *http.Response

获取原始Response对象

func (*HttpResponse) Status

func (r *HttpResponse) Status() int

状态码

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL