ht

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 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 added in v0.0.39

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

DeleteURL 发送DELETE表单请求

func Get

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

Get 发送GET表单请求

func GetURL added in v0.0.39

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

GetURL 发送GET表单请求

func Httpclient added in v0.0.39

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 added in v0.0.52

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 added in v0.0.52

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 added in v0.0.39

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

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

func PostJsonStruct added in v0.0.39

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 added in v0.0.39

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

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

func PutJsonStruct added in v0.0.39

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

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

func ReadBody added in v0.0.3

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

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

func ReadBodyAndHeader added in v0.0.52

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

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

func ReadBodyAndHeaderAndStatusCode added in v0.0.52

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

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

func ReadBodyAndStatusCode added in v0.0.52

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

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

func SetProxy added in v0.0.39

func SetProxy(proxyRaw string) error

SetProxy 设置代理

func SetTimeout added in v0.0.39

func SetTimeout(timeoutSecond uint)

SetTimeout 设置超时时间

func SetUrlLog added in v0.0.39

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

SetUrlLog 设置请求链接打印日志

func SetUserAgent added in v0.0.39

func SetUserAgent(ua string)

SetUserAgent 设置UA信息

Types

type HttpClient added in v0.0.39

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 added in v0.0.39

func Proxy(proxyRaw string) *HttpClient

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

func Timeout added in v0.0.39

func Timeout(timeoutSecond uint) *HttpClient

Timeout 设置临时超时时间

func UA added in v0.0.39

func UA(ua string) *HttpClient

UA 设置临时User-Agent

func (*HttpClient) DELETE added in v0.0.39

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

DELETE 发送DELETE表单请求

func (*HttpClient) GET added in v0.0.39

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

GET 发送GET表单请求

func (*HttpClient) HttpClient added in v0.0.39

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

HttpClient 返回一个http客户端

func (*HttpClient) POST added in v0.0.39

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

POST 发送POST表单请求

func (*HttpClient) PUT added in v0.0.39

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

PUT 发送PUT表单请求

func (*HttpClient) PostBody added in v0.0.39

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

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

func (*HttpClient) PostJsonMap added in v0.0.39

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

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

func (*HttpClient) PostJsonStruct added in v0.0.39

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

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

func (*HttpClient) Proxy added in v0.0.39

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 added in v0.0.39

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

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

func (*HttpClient) PutJsonMap added in v0.0.39

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

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

func (*HttpClient) PutJsonStruct added in v0.0.39

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

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

func (*HttpClient) SetProxy added in v0.0.39

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

SetProxy 设置代理

func (*HttpClient) SetTimeout added in v0.0.39

func (c *HttpClient) SetTimeout(timeoutSecond uint)

SetTimeout 设置超时时间

func (*HttpClient) SetUrlLog added in v0.0.39

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

SetUrlLog 设置请求链接打印日志

func (*HttpClient) SetUserAgent added in v0.0.39

func (c *HttpClient) SetUserAgent(ua string)

SetUserAgent 设置UA信息

func (*HttpClient) Timeout added in v0.0.39

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

Timeout 设置临时超时时间

func (*HttpClient) UA added in v0.0.39

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

UA 设置临时User-Agent

type Method added in v0.0.3

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

type Params added in v0.0.39

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

type ParamsItem added in v0.0.39

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

type RequestParams added in v0.0.3

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

func Merge added in v0.0.3

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

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

func NewRequestParams added in v0.0.3

func NewRequestParams() RequestParams

func ParseParamsString added in v0.0.39

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

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

type UserAgent added in v0.0.3

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