http

package
v0.19.3 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(url string, headers, params map[string]string, timeout int64) ([]byte, error)

Get GET 请求,包含超时时间 params 添加到 url 上 timeout 超时时间,秒 eg: url := "https://www.keylala.cn" params := map[string]string{"name": "Alex", "id": "1001"} Get(url, nil, params, 5)

func GetJSON

func GetJSON(url string, headers, params map[string]string, timeout int64, out interface{}) error

GetJSON GET 请求,包含超时时间,结果转为 JSON params 添加到 url 上 timeout 超时时间,秒 out 结果写入于此,可以是 nil,指针

func GetRetry

func GetRetry(url string, headers, params map[string]string, timeout int64, retryCount, sleep uint) ([]byte, error)

GetRetry GET 请求,包含超时时间,重试次数 timeout 超时时间,秒 retryCount 重试次数 sleep 重试之间 sleep 时间,毫秒 eg: url := "https://www.keylala.cn"

每次请求超时时间为 5 秒 如果请求失败,则重试,直到 3 次为止 每次重试之间 Sleep 500 毫秒 GetRetry(url, nil, nil, 5, 3, 500)

func GetString

func GetString(url string, headers, params map[string]string, timeout int64) (string, error)

GetString GET 请求,包含超时时间,结果转为字符串 params 添加到 url 上 timeout 超时时间,秒 eg: url := "https://www.keylala.cn" GetString(url, nil, nil, 5)

func Post

func Post(url string, headers, params, body map[string]string, timeout int64) ([]byte, error)

Post POST 请求(JSON 格式),包含超时时间 params 添加到 url 上 body 添加到 body 上 timeout 超时时间,秒 eg: url := "https://www.keylala.cn" params := map[string]string{"name": "Alex", "id": "1001"} Post(url, nil, params, 5)

func PostJSON

func PostJSON(url string, headers, params map[string]string, timeout int64, out interface{}) error

PostJSON POST 请求,包含超时时间,结果转为 JSON params 添加到 url 上 timeout 超时时间,秒 out 结果写入于此,可以是 nil,指针

func PostRetry

func PostRetry(url string, headers, params, body map[string]string, timeout int64, retryCount, sleep uint) ([]byte, error)

PostRetry POST 请求,包含超时时间,重试次数 timeout 超时时间,秒 eg: url := "https://www.keylala.cn"

每次请求超时时间为 5 秒 如果请求失败,则重试,直到 3 次为止 每次重试之间 Sleep 500 毫秒 PostRetry(url, nil, nil, 5, 3, 500)

func PostString

func PostString(url string, headers, params map[string]string, timeout int64) (string, error)

PostString POST 请求,包含超时时间,结果转为字符串 params 添加到 url 上 timeout 超时时间,秒 eg: url := "https://www.keylala.cn" PostString(url, nil, nil, 5)

func SetDisableKeepAlives

func SetDisableKeepAlives(enable bool)

SetDisableKeepAlives 设置 defaultDisableKeepAlives

func SetMaxIdleConnsPerHost

func SetMaxIdleConnsPerHost(count int)

SetMaxIdleConnsPerHost 设置 defaultMaxIdleConnsPerHost

Types

This section is empty.

Jump to

Keyboard shortcuts

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