http

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewH2CHTTP

func NewH2CHTTP(timeout int) *Client

NewH2CHTTP 创建新的H2C客户端,timeout单位为毫秒 NewH2CHTTP return H2C客户端对象,支持的方法:get、post、put、delete、head、setBaseURL、setGlobalHeaders

func NewHTTP

func NewHTTP(timeout int) *Client

NewHTTP 创建新的HTTP客户端 * timeout 请求的超时时间,单位(毫秒) NewHTTP return HTTP客户端对象,支持的方法:get、post、put、delete、head、setBaseURL、setGlobalHeaders

func (*Client) Delete

func (c *Client) Delete(logger *log.Logger, url string, body interface{}, headers *map[string]string) (map[string]interface{}, error)

Delete 发送DELETE请求

func (*Client) Get

func (c *Client) Get(logger *log.Logger, url string, headers *map[string]string) (map[string]interface{}, error)

Get 发送GET请求 * url 以http://或https://开头的URL地址,如果设置了baseURL可以只提供path部分 * headers 传入一个Key-Value对象的HTTP头信息,如果不指定头信息这个参数可以省略不传 * return 返回结果对象,如果返回值是JSON格式,将自动转化为对象否则将字符串放在.result中,如发生错误将抛出异常,返回的对象中还包括:headers、statusCode、statusMessage

func (*Client) Head

func (c *Client) Head(logger *log.Logger, url string, body interface{}, headers *map[string]string) (map[string]interface{}, error)

Head 发送HEAD请求

func (*Client) Post

func (c *Client) Post(logger *log.Logger, url string, body interface{}, headers *map[string]string) (map[string]interface{}, error)

Post 发送POST请求 * body 可以传入任意类型,如果不是字符串或二进制数组时会自动添加application/json头,数据将以json格式发送

func (*Client) Put

func (c *Client) Put(logger *log.Logger, url string, body interface{}, headers *map[string]string) (map[string]interface{}, error)

Put 发送PUT请求

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(url string)

SetBaseURL 设置一个URL前缀,后续请求中可以只提供path部分 SetBaseURL url 以http://或https://开头的URL地址

func (*Client) SetGlobalHeaders

func (c *Client) SetGlobalHeaders(headers map[string]string)

SetGlobalHeaders 设置固定的HTTP头部信息,在每个请求中都加入这些HTTP头 SetGlobalHeaders headers 传入一个Key-Value对象的HTTP头信息

Jump to

Keyboard shortcuts

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