request

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultUserAgent     = "req/v3 (https://github.com/imroc/req)"
	UserAgent            = "User-Agent"
	Location             = "Location"
	ContentType          = "Content-Type"
	PlainTextContentType = "text/plain; charset=utf-8"
	JsonContentType      = "application/json; charset=utf-8"
	XmlContentType       = "text/xml; charset=utf-8"
	FormContentType      = "application/x-www-form-urlencoded"
	WwwAuthenticate      = "WWW-Authenticate"
	Authorization        = "Authorization"
	HeaderOderKey        = "__header_order__"
	PseudoHeaderOderKey  = "__pseudo_header_order__"
)

Variables

This section is empty.

Functions

func IsJSONType

func IsJSONType(ct string) bool

IsJSONType method is to check JSON content type or not

func IsXMLType

func IsXMLType(ct string) bool

IsXMLType method is to check XML content type or not

Types

type Client

type Client struct {
	PathParams            map[string]string
	AllowGetMethodPayload bool
	// contains filtered or unexported fields
}

type GetContentFunc

type GetContentFunc func() (io.ReadCloser, error)

type Request

type Request struct {
	Headers    http.Header    // 请求头
	RawRequest *http.Request  // 请求对象
	RowUrl     string         // 请求地址
	URL        *url.URL       // 请求地址结构体
	Method     string         // 请求方式
	Body       []byte         // 请求请求主体
	GetBody    GetContentFunc // 获取请求主体方法
	Cookies    []*http.Cookie // cookie
	Timeout    time.Duration  // 超时时间
	Queries    map[string]string
	// contains filtered or unexported fields
}

func New

func New() *Request

func (*Request) Do

func (r *Request) Do(ctx context.Context) (resp *Response, err error)

func (*Request) Request

func (r *Request) Request(method, rowUrl string) *Request

func (*Request) SetBody

func (r *Request) SetBody(body interface{}) *Request

func (*Request) SetBodyBytes

func (r *Request) SetBodyBytes(body []byte) *Request

func (*Request) SetBodyJsonBytes

func (r *Request) SetBodyJsonBytes(body []byte) *Request

func (*Request) SetBodyString

func (r *Request) SetBodyString(body string) *Request

func (*Request) SetContentType

func (r *Request) SetContentType(contentType string) *Request

func (*Request) SetFormData

func (r *Request) SetFormData(data map[string]string) *Request

func (*Request) SetHeader

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

func (*Request) SetHeaders

func (r *Request) SetHeaders(headers map[string]string) *Request

func (*Request) SetMethod added in v0.0.4

func (r *Request) SetMethod(method string) *Request

func (*Request) SetQuery added in v0.0.4

func (r *Request) SetQuery(queries map[string]string) *Request

func (*Request) SetRowUrl added in v0.0.4

func (r *Request) SetRowUrl(rowUrl string) *Request

type RequestMiddleware

type RequestMiddleware func(client *Client, req *Request) error

RequestMiddleware type is for request middleware, called before a request is sent

type Response

type Response struct {
	*http.Response
	Request *Request
	// contains filtered or unexported fields
}

func Get

func Get(url string) (resp *Response, err error)

func Post

func Post(url string, body interface{}, form map[string]string) (resp *Response, err error)

func (*Response) String

func (r *Response) String() string

func (*Response) ToBytes

func (r *Response) ToBytes() (body []byte, err error)

func (*Response) UnmarshalJson

func (r *Response) UnmarshalJson(v interface{}) error

type ResponseMiddleware

type ResponseMiddleware func(client *Client, resp *Response) error

ResponseMiddleware type is for response middleware, called after a response has been received

type RetryHookFunc

type RetryHookFunc func(resp *Response, err error)

type RoundTripper

type RoundTripper interface {
	RoundTrip(context.Context, *Request) (*Response, error)
}

Jump to

Keyboard shortcuts

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