gorequest

package module
v1.0.51 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 25 Imported by: 46

README

Golang

📦 Golang 请求

godoc goproxy.cn goreportcard.com deps.dev

安装

go get -v -u go.dtapp.net/gorequest@v1.0.51

Documentation

Index

Constants

View Source
const Version = "1.0.51"

Variables

This section is empty.

Functions

func ClientIp

func ClientIp(r *http.Request) string

ClientIp 尽最大努力实现获取客户端 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。

func DeCode added in v1.0.19

func DeCode(s string) string

DeCode 解码

func GetCmdOutsideIP added in v1.0.50

func GetCmdOutsideIP() string

GetCmdOutsideIP 通过命令获取外网IP

func GetInsideIp added in v1.0.40

func GetInsideIp(ctx context.Context) string

GetInsideIp 内网IP

func GetMacAddr added in v1.0.40

func GetMacAddr(ctx context.Context) (arrays []string)

GetMacAddr 获取Mac地址

func GetOutsideIPV4All added in v1.0.50

func GetOutsideIPV4All(ctx context.Context) string

GetOutsideIPV4All 外网IPV4地址

func GetOutsideIPV6All added in v1.0.50

func GetOutsideIPV6All(ctx context.Context) string

GetOutsideIPV6All 外网IPV6地址

func GetOutsideIp added in v1.0.40

func GetOutsideIp(ctx context.Context) string

GetOutsideIp 外网IP

func GetParamsString

func GetParamsString(src interface{}) string

GetParamsString 获取参数字符串

func GetRandomUserAgent

func GetRandomUserAgent() string

GetRandomUserAgent 获取随机UA

func GetRandomUserAgentSystem

func GetRandomUserAgentSystem() string

GetRandomUserAgentSystem 获取系统随机UA

func Ips added in v1.0.40

func Ips(ctx context.Context) (map[string]string, error)

Ips 获取全部网卡的全部IP

func IsIPV4 added in v1.0.50

func IsIPV4(s string) bool

func IsIPV6 added in v1.0.50

func IsIPV6(s string) bool

func IsIPv4Public added in v1.0.50

func IsIPv4Public(ip net.IP) bool

func IsIPv6Public added in v1.0.50

func IsIPv6Public(ip net.IP) bool

func IsWechatMiniProgramRequest added in v1.0.39

func IsWechatMiniProgramRequest(r *http.Request, appid string) error

IsWechatMiniProgramRequest 判断是否是微信小程序

func LenCode added in v1.0.19

func LenCode(s string) string

LenCode 编码

func ParseQuery added in v1.0.19

func ParseQuery(s string) map[string][]string

ParseQuery 获取URL参数 https://studygolang.com/articles/2876

func ToXml added in v1.0.39

func ToXml(params map[string]interface{}) (reader io.Reader, err error)

Types

type App

type App struct {
	Uri   string // 全局请求地址,没有设置url才会使用
	Error error  // 错误
	// contains filtered or unexported fields
}

App 实例

func NewHttp

func NewHttp() *App

NewHttp 实例化

func (*App) Get

func (app *App) Get(ctx context.Context, uri ...string) (httpResponse Response, err error)

Get 发起GET请求

func (*App) Post

func (app *App) Post(ctx context.Context, uri ...string) (httpResponse Response, err error)

Post 发起POST请求

func (*App) Request

func (app *App) Request(ctx context.Context) (httpResponse Response, err error)

Request 发起请求

func (*App) SetAuthToken

func (app *App) SetAuthToken(token string)

SetAuthToken 设置身份验证令牌

func (*App) SetContentTypeForm

func (app *App) SetContentTypeForm()

SetContentTypeForm 设置FORM格式

func (*App) SetContentTypeJson

func (app *App) SetContentTypeJson()

SetContentTypeJson 设置JSON格式

func (*App) SetContentTypeXml

func (app *App) SetContentTypeXml()

SetContentTypeXml 设置XML格式

func (*App) SetCookie added in v1.0.39

func (app *App) SetCookie(cookie string)

SetCookie 设置Cookie

func (*App) SetDebug

func (app *App) SetDebug()

SetDebug 设置调试模式

func (*App) SetHeader

func (app *App) SetHeader(key, value string)

SetHeader 设置请求头

func (*App) SetHeaders

func (app *App) SetHeaders(headers Headers)

SetHeaders 批量设置请求头

func (*App) SetMethod

func (app *App) SetMethod(method string)

SetMethod 设置请求方式

func (*App) SetP12Cert

func (app *App) SetP12Cert(content *tls.Certificate)

SetP12Cert 设置证书

func (*App) SetParam

func (app *App) SetParam(key string, value interface{})

SetParam 设置请求参数

func (*App) SetParams

func (app *App) SetParams(params Params)

SetParams 批量设置请求参数

func (*App) SetTlsVersion added in v1.0.39

func (app *App) SetTlsVersion(minVersion, maxVersion uint16)

SetTlsVersion 设置TLS版本

func (*App) SetUri

func (app *App) SetUri(uri string)

SetUri 设置请求地址

func (*App) SetUserAgent

func (app *App) SetUserAgent(ua string)

SetUserAgent 设置用户代理,传空字符串就随机设置

type Headers

type Headers map[string]string

Headers 头部信息

func NewHeaders

func NewHeaders() Headers

NewHeaders 新建头部信息

func NewNewHeadersWith

func NewNewHeadersWith(headers ...Headers) Headers

NewNewHeadersWith 头部信息使用

func (*Headers) DeepCopy

func (h *Headers) DeepCopy() map[string]string

DeepCopy 深度复制

func (Headers) GetQuery

func (h Headers) GetQuery() string

GetQuery 获取头部信息

func (Headers) Set

func (h Headers) Set(key, value string)

Set 设置头部信息

func (Headers) SetHeaders

func (h Headers) SetHeaders(headers Headers)

SetHeaders 批量设置头部信息

type Params

type Params map[string]interface{}

Params 参数

func NewParams

func NewParams() Params

NewParams 新建参数

func NewParamsWith

func NewParamsWith(params ...Params) Params

NewParamsWith 参数使用

func (*Params) DeepCopy

func (p *Params) DeepCopy() map[string]interface{}

DeepCopy 深度复制

func (Params) Get added in v1.0.39

func (p Params) Get(key string) interface{}

Get 获取参数

func (Params) Set

func (p Params) Set(key string, value interface{})

Set 设置参数

func (Params) SetParams

func (p Params) SetParams(params Params)

SetParams 批量设置参数

type Response

type Response struct {
	RequestId             string      //【请求】编号
	RequestUri            string      //【请求】链接
	RequestParams         Params      //【请求】参数
	RequestMethod         string      //【请求】方式
	RequestHeader         Headers     //【请求】头部
	RequestCookie         string      //【请求】Cookie
	RequestTime           time.Time   //【请求】时间
	ResponseHeader        http.Header //【返回】头部
	ResponseStatus        string      //【返回】状态
	ResponseStatusCode    int         //【返回】状态码
	ResponseBody          []byte      //【返回】内容
	ResponseContentLength int64       //【返回】大小
	ResponseTime          time.Time   //【返回】时间
}

Response 返回内容

func (*Response) HeaderHtml added in v1.0.28

func (r *Response) HeaderHtml() bool

HeaderHtml 判断是否为Html

func (*Response) HeaderIsImg added in v1.0.28

func (r *Response) HeaderIsImg() bool

HeaderIsImg 判断是否为图片

func (*Response) HeaderIsJpeg added in v1.0.28

func (r *Response) HeaderIsJpeg() bool

HeaderIsJpeg 判断是否为jpeg图片

func (*Response) HeaderIsJpg added in v1.0.28

func (r *Response) HeaderIsJpg() bool

HeaderIsJpg 判断是否为Jpg图片

func (*Response) HeaderIsPng added in v1.0.28

func (r *Response) HeaderIsPng() bool

HeaderIsPng 判断是否为Png图片

func (*Response) HeaderJson added in v1.0.28

func (r *Response) HeaderJson() bool

HeaderJson 判断是否为Json数据

func (*Response) HeaderTextHtml added in v1.0.28

func (r *Response) HeaderTextHtml() bool

HeaderTextHtml 判断是否为Html

func (*Response) HeaderXHtml added in v1.0.28

func (r *Response) HeaderXHtml() bool

HeaderXHtml 判断是否为Html

type ResponseUrlParse

type ResponseUrlParse struct {
	Uri      string `json:"uri"`       // URI
	Urn      string `json:"urn"`       // URN
	Url      string `json:"url"`       // URL
	Scheme   string `json:"scheme"`    // 协议
	Host     string `json:"host"`      // 主机
	Hostname string `json:"hostname"`  // 主机名
	Port     string `json:"port"`      // 端口
	Path     string `json:"path"`      // 路径
	RawQuery string `json:"raw_query"` // 参数 ?
	Fragment string `json:"fragment"`  // 片段 #
}

ResponseUrlParse 返回参数

type UriParse

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

func NewUri added in v1.0.29

func NewUri(uri string) *UriParse

func (*UriParse) Parse added in v1.0.29

func (u *UriParse) Parse() (resp ResponseUrlParse)

Parse 解析URl

func (*UriParse) UriFilterExcludeQueryString added in v1.0.29

func (u *UriParse) UriFilterExcludeQueryString(uri string) string

UriFilterExcludeQueryString 过滤掉url中的参数

Jump to

Keyboard shortcuts

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