ht

package module
v0.0.0-...-9e1280c Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentType = "Content-Type"
)

Variables

This section is empty.

Functions

func Delete

func Delete(urlRaw string, params RequestParams) (*http.Response, error)

Delete 发送DELETE表单请求

func DeleteURL

func DeleteURL(urlRaw string) (*http.Response, error)

DeleteURL 发送DELETE表单请求

func Get

func Get(urlRaw string, params RequestParams) (*http.Response, error)

Get 发送GET表单请求

func GetURL

func GetURL(urlRaw string) (*http.Response, error)

GetURL 发送GET表单请求

func Httpclient

func Httpclient() *http.Client

Httpclient 返回一个http客户端

func NewHeaders

func NewHeaders(ua UserAgent) map[string]string

NewHeaders 创建一个浏览器header UA

func NewProxy

func NewProxy(rawurl string) (*http.Transport, error)

NewProxy 创建一个代理,用于发送请求的时候使用,假如代理链接错误,则返回&http.Transport{},error。 NewProxy("socks5://127.0.0.1:1080") NewProxy("socks5://admin:password@192.168.1.2:8888") NewProxy("http://127.0.0.1:1081") NewProxy("http://admin:password@192.168.1.2:8889")

func NewProxyTransport

func NewProxyTransport(rawurl string) (*http.Transport, error)

NewProxyTransport 创建一个代理,用于发送请求的时候使用,假如代理链接有错,则返回nil,error。 NewProxyTransport("socks5://127.0.0.1:1080") NewProxyTransport("socks5://admin:password@192.168.1.2:8888") NewProxyTransport("http://127.0.0.1:1081") NewProxyTransport("http://admin:password@192.168.1.2:8889")

func NewTransport

func NewTransport(rawurl string) *http.Transport

NewTransport 创建一个代理,用于发送请求的时候使用,假如代理链接错误,则返回&http.Transport{},error。 NewTransport("socks5://127.0.0.1:1080") NewTransport("socks5://admin:password@192.168.1.2:8888") NewTransport("http://127.0.0.1:1081") NewTransport("http://admin:password@192.168.1.2:8889")

func Post

func Post(urlRaw string, params RequestParams) (*http.Response, error)

Post 发送POST表单请求

func PostBody

func PostBody(urlRaw string, params RequestParams, body []byte, contentType string) (*http.Response, error)

PostBody 发送POST请求,请求体为body

func PostJsonMap

func PostJsonMap(urlRaw string, params RequestParams, jsonData map[string]any) (*http.Response, error)

PostJsonMap 发送POST请求,请求体为jsonData和params.Body合并的json编码结果

func PostJsonStruct

func PostJsonStruct(urlRaw string, params RequestParams, structPointer any) (*http.Response, error)

PostJsonStruct 发送POST请求,请求体为structPointer和params.Body合并的json编码结果

func Put

func Put(urlRaw string, params RequestParams) (*http.Response, error)

Put 发送PUT表单请求

func PutBody

func PutBody(urlRaw string, params RequestParams, body []byte, contentType string) (*http.Response, error)

PutBody 发送PUT请求,请求体为body

func PutJsonMap

func PutJsonMap(urlRaw string, params RequestParams, jsonData map[string]any) (*http.Response, error)

PutJsonMap 发送PUT请求,请求体为jsonData和params.Body合并的json编码结果

func PutJsonStruct

func PutJsonStruct(urlRaw string, params RequestParams, structPointer any) (*http.Response, error)

PutJsonStruct 发送PUT请求,请求体为structPointer和params.Body合并的json编码结果

func ReadBody

func ReadBody(resp *http.Response, err error) ([]byte, error)

ReadBody 读取响应体,丢弃其它内容。

func ReadBodyAndHeader

func ReadBodyAndHeader(resp *http.Response, err error) ([]byte, http.Header, error)

ReadBodyAndHeader 读取响应体和响应头,丢弃其它内容。

func ReadBodyAndHeaderAndStatusCode

func ReadBodyAndHeaderAndStatusCode(resp *http.Response, err error) ([]byte, http.Header, int, error)

ReadBodyAndHeaderAndStatusCode 读取响应体和响应头、响应状态码,丢弃其它内容。

func ReadBodyAndStatusCode

func ReadBodyAndStatusCode(resp *http.Response, err error) ([]byte, int, error)

ReadBodyAndStatusCode 读取响应体和响应状态码,丢弃其它内容。

func SetProxy

func SetProxy(proxyRaw string) error

SetProxy 设置代理

func SetTimeout

func SetTimeout(timeoutSecond uint)

SetTimeout 设置超时时间

func SetUrlLog

func SetUrlLog(fx func(a ...any))

SetUrlLog 设置请求链接打印日志

func SetUserAgent

func SetUserAgent(ua string)

SetUserAgent 设置UA信息

Types

type HttpClient

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

func NewClient

func NewClient(proxyRaw string, timeoutSecond uint, ua UserAgent) *HttpClient

NewClient 创建一个http请求的客户端 proxyRaw 代理信息,空值则不使用代理;非空:"socks5://192.168.1.2:1080" "socks5://admin:password@192.168.1.2:8888" timeoutSecond 请求超时时间,秒

func Proxy

func Proxy(proxyRaw string) *HttpClient

Proxy 设置临时代理 proxyRaw 代理信息,空值则不使用代理;非空:"socks5://127.0.0.1:1080" "socks5://admin:password@192.168.1.2:8888"

func Timeout

func Timeout(timeoutSecond uint) *HttpClient

Timeout 设置临时超时时间

func UA

func UA(ua string) *HttpClient

UA 设置临时User-Agent

func (*HttpClient) DELETE

func (c *HttpClient) DELETE(urlRaw string, params RequestParams) (*http.Response, error)

DELETE 发送DELETE表单请求

func (*HttpClient) GET

func (c *HttpClient) GET(urlRaw string, params RequestParams) (*http.Response, error)

GET 发送GET表单请求

func (*HttpClient) HttpClient

func (c *HttpClient) HttpClient() *http.Client

HttpClient 返回一个http客户端

func (*HttpClient) POST

func (c *HttpClient) POST(urlRaw string, params RequestParams) (*http.Response, error)

POST 发送POST表单请求

func (*HttpClient) PUT

func (c *HttpClient) PUT(urlRaw string, params RequestParams) (*http.Response, error)

PUT 发送PUT表单请求

func (*HttpClient) PostBody

func (c *HttpClient) PostBody(urlRaw string, params RequestParams, body []byte, contentType string) (*http.Response, error)

PostBody 发送POST请求,请求体为body

func (*HttpClient) PostJsonMap

func (c *HttpClient) PostJsonMap(urlRaw string, params RequestParams, jsonData map[string]any) (*http.Response, error)

PostJsonMap 发送POST请求,请求体为jsonData和params.Body合并的json编码结果

func (*HttpClient) PostJsonStruct

func (c *HttpClient) PostJsonStruct(urlRaw string, params RequestParams, structPointer any) (*http.Response, error)

PostJsonStruct 发送POST请求,请求体为structPointer和params.Body合并的json编码结果

func (*HttpClient) Proxy

func (c *HttpClient) Proxy(proxyRaw string) *HttpClient

Proxy 设置临时代理 proxyRaw 代理信息,空值则不使用代理;非空:"socks5://127.0.0.1:1080" "socks5://admin:password@192.168.1.2:8888"

func (*HttpClient) PutBody

func (c *HttpClient) PutBody(urlRaw string, params RequestParams, body []byte, contentType string) (*http.Response, error)

PutBody 发送PUT请求,请求体为body

func (*HttpClient) PutJsonMap

func (c *HttpClient) PutJsonMap(urlRaw string, params RequestParams, jsonData map[string]any) (*http.Response, error)

PutJsonMap 发送PUT请求,请求体为jsonData和params.Body合并的json编码结果

func (*HttpClient) PutJsonStruct

func (c *HttpClient) PutJsonStruct(urlRaw string, params RequestParams, structPointer any) (*http.Response, error)

PutJsonStruct 发送PUT请求,请求体为structPointer和params.Body合并的json编码结果

func (*HttpClient) SetProxy

func (c *HttpClient) SetProxy(proxyRaw string) error

SetProxy 设置代理

func (*HttpClient) SetTimeout

func (c *HttpClient) SetTimeout(timeoutSecond uint)

SetTimeout 设置超时时间

func (*HttpClient) SetUrlLog

func (c *HttpClient) SetUrlLog(fx func(a ...any))

SetUrlLog 设置请求链接打印日志

func (*HttpClient) SetUserAgent

func (c *HttpClient) SetUserAgent(ua string)

SetUserAgent 设置UA信息

func (*HttpClient) Timeout

func (c *HttpClient) Timeout(timeoutSecond uint) *HttpClient

Timeout 设置临时超时时间

func (*HttpClient) UA

func (c *HttpClient) UA(ua string) *HttpClient

UA 设置临时User-Agent

type Method

type Method string
const (
	GET    Method = "GET"
	POST   Method = "POST"
	PUT    Method = "PUT"
	DELETE Method = "DELETE"
)

type Params

type Params struct {
	Header []ParamsItem `json:"header"`
	Query  []ParamsItem `json:"query"`
	Body   []ParamsItem `json:"body"`
}

type ParamsItem

type ParamsItem struct {
	Id    int    `json:"id"`
	Field string `json:"field"`
	Value string `json:"value"`
}

type RequestParams

type RequestParams struct {
	Header map[string]string
	Query  map[string]string
	Body   map[string]any
}

func Merge

func Merge(global RequestParams, local RequestParams, custom RequestParams) RequestParams

Merge 将 local 合并到 global,然后将 custom 合并到 global ,最后返回 global。

func NewRequestParams

func NewRequestParams() RequestParams

func ParseParamsString

func ParseParamsString(ps ...string) (RequestParams, error)

ParseParamsString 解析指定格式的参数json,内容格式必须是 Params 的json编码结果。

type UserAgent

type UserAgent string
const (
	UaPcWinMicrosoftEdge   UserAgent = `` /* 129-byte string literal not displayed */
	UaPcWinFirefox         UserAgent = `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0`
	UaPcWinGoogleChrome    UserAgent = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36`
	UaPcWin360Browser      UserAgent = `Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36`
	UaPcWin360JiSuBrowser  UserAgent = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4621.0 Safari/537.36`
	UaPcWinSougouBrowser   UserAgent = `` /* 127-byte string literal not displayed */
	UaAndroidUCBrowser     UserAgent = `` /* 159-byte string literal not displayed */
	UaAndroidHuaWeiBrowser UserAgent = `` /* 134-byte string literal not displayed */
)

Jump to

Keyboard shortcuts

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