httpUtils

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2019 License: GPL-3.0 Imports: 9 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 added in v1.0.5

func GetClient() *http.Client

获取客户端

func SetClient added in v1.0.5

func SetClient(opts ClientOptions)

设置客户端

Types

type ClientOptions added in v1.0.5

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

type HttpRequest added in v1.0.5

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

func Request added in v1.0.5

func Request() *HttpRequest

新请求

func RequestWithClient added in v1.0.5

func RequestWithClient(client *http.Client) *HttpRequest

新请求,自己设置Client实例

func (*HttpRequest) AcceptJSON added in v1.0.5

func (r *HttpRequest) AcceptJSON() *HttpRequest

期望JSON响应

func (*HttpRequest) AddHeader added in v1.0.5

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

添加请求头

func (*HttpRequest) AddQuery added in v1.0.5

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

添加查询参数

func (*HttpRequest) Body added in v1.0.5

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

设置请求体

func (*HttpRequest) Clone added in v1.0.5

func (r *HttpRequest) Clone() *HttpRequest

复制一份请求

func (*HttpRequest) DELETE added in v1.0.5

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

DELETE

func (*HttpRequest) GET added in v1.0.5

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

GET

func (*HttpRequest) HEAD added in v1.0.5

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

HEAD

func (*HttpRequest) JSON added in v1.0.5

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

设置JSON请求体

func (*HttpRequest) OPTIONS added in v1.0.5

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

OPTIONS

func (*HttpRequest) POST added in v1.0.5

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

POST

func (*HttpRequest) PUT added in v1.0.5

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

PUT

func (*HttpRequest) Send added in v1.0.5

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

发送请求

func (*HttpRequest) SetHeader added in v1.0.5

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

设置请求头

func (*HttpRequest) SetQuery added in v1.0.5

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

设置查询参数

func (*HttpRequest) TRACE added in v1.0.5

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

TRACE

type HttpResponse added in v1.0.5

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

func (*HttpResponse) Body added in v1.0.5

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

响应体

func (*HttpResponse) Close added in v1.0.5

func (r *HttpResponse) Close() error

关闭

func (*HttpResponse) Header added in v1.0.5

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

响应天

func (*HttpResponse) JSON added in v1.0.5

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

JSON响应体

func (*HttpResponse) MustBody added in v1.0.5

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

响应体,如果出错则panic

func (*HttpResponse) Origin added in v1.0.5

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

获取原始Response对象

func (*HttpResponse) Status added in v1.0.5

func (r *HttpResponse) Status() int

状态码

Jump to

Keyboard shortcuts

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