request

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package request 本项目对外发起请求使用此包

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(l *logrus.Entry)

SetLogger 设置全局 log 输出对象

Types

type Request

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

Request 请求数据

func URL

func URL(url string) *Request

URL 构造请求 默认使用 GET 请求

func (*Request) Body

func (req *Request) Body(body []byte) *Request

Body 指定 body 参数

func (*Request) ContentType

func (req *Request) ContentType(contentType string) *Request

ContentType 指定传参类型

func (*Request) Do

func (req *Request) Do() (*Response, error)

Do 发起请求

func (*Request) HTTPRequest

func (req *Request) HTTPRequest() (*http.Request, error)

HTTPRequest 构造 *http.Request 对象

func (*Request) Header

func (req *Request) Header(header http.Header) *Request

Header 指定header

func (*Request) Method

func (req *Request) Method(method string) *Request

Method 指定请求方式

func (*Request) Parameters

func (req *Request) Parameters(parameters url.Values) *Request

Parameters 指定 url 参数

type Response

type Response struct {
	*http.Response
}

Response 扩展 *http.Response 的功能

func Do

func Do(req *Request) (*Response, error)

Do 发起请求

func (*Response) Unmarshal

func (response *Response) Unmarshal(v interface{}) error

Unmarshal 将 response 数据当作 json 转换为结构体或map

Jump to

Keyboard shortcuts

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