request

package
v1.0.22 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: MIT Imports: 13 Imported by: 0

README

HttpRequest

Usage
1.异步http request时,需要初始化异步请求池,写在main里
// 需要异步http时,poolSize值10~100
request.InitAsyncRequestPool(poolSize) 

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitAsyncPool

func InitAsyncPool(poolSize int)

InitAsyncPool 初始化异步请求池

Types

type ErrorMessage added in v1.0.15

type ErrorMessage struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

type HttpRequest

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

func NewHttpRequest

func NewHttpRequest(url string) *HttpRequest

NewHttpRequest 创建Http请求

func (*HttpRequest) AddHeader

func (req *HttpRequest) AddHeader(header, val string) *HttpRequest

AddHeader 增加一个Header

func (*HttpRequest) Response

func (req *HttpRequest) Response() ([]byte, error)

Response 原始http请求(返回byte)

func (*HttpRequest) Result

func (req *HttpRequest) Result() (*HttpResponse, error)

Result http请求 返回封装

func (*HttpRequest) SetAsync

func (req *HttpRequest) SetAsync(on bool) *HttpRequest

SetAsync 设置异步

func (*HttpRequest) SetContentType

func (req *HttpRequest) SetContentType(typeStr string) *HttpRequest

SetContentType 设置ContentType

func (*HttpRequest) SetCookies

func (req *HttpRequest) SetCookies(cookies map[string]string) *HttpRequest

SetCookies 设置cookies

func (*HttpRequest) SetFormBody

func (req *HttpRequest) SetFormBody(body map[string]interface{}) *HttpRequest

SetFormBody 设置

func (*HttpRequest) SetFormDataBody

func (req *HttpRequest) SetFormDataBody(body map[string]interface{}) *HttpRequest

SetFormDataBody 设置文件上传 文件路径名map/文件二进制内容map

func (*HttpRequest) SetHeaders

func (req *HttpRequest) SetHeaders(headers map[string]string) *HttpRequest

SetHeaders 设置Headers

func (*HttpRequest) SetMethod

func (req *HttpRequest) SetMethod(method string) *HttpRequest

SetMethod 设置Http请求方法

func (*HttpRequest) SetQueries

func (req *HttpRequest) SetQueries(queries map[string]string) *HttpRequest

SetQueries 设置url携带的数据

func (*HttpRequest) SetRawBody

func (req *HttpRequest) SetRawBody(body []byte) *HttpRequest

SetRawBody raw参数

func (*HttpRequest) SetTimeout

func (req *HttpRequest) SetTimeout(timeout time.Duration) *HttpRequest

SetTimeout 设置超时

func (*HttpRequest) SetTracing

func (req *HttpRequest) SetTracing(span opentracing.Span) *HttpRequest

SetTracing 设置追踪

func (*HttpRequest) Unmarshal

func (req *HttpRequest) Unmarshal(data interface{}) error

Unmarshal HTTP请求(填充data结构体信息)

type HttpResponse

type HttpResponse struct {
	Success bool         `json:"success"`
	Data    interface{}  `json:"data"`
	Error   ErrorMessage `json:"error"`
}

Jump to

Keyboard shortcuts

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