package
0.49.11
Repository: https://github.com/zerogo-hub/zero-helper.git
Documentation: pkg.go.dev

# README

简述

方便使用的http

功能

  • 链式调用
  • 超时设置
  • 代理
  • 缓存

使用

基本使用

client := zerohttpclient.NewClient()

ctx := client.Get("https://www.keylala.cn")
result, _ := ctx.ToString()
fmt.Println(result)

添加参数

client := zerohttpclient.NewClient()

ctx := client.WithParams(map[string]interface{}{
    "id": "123456",
    "name": "zero",
}).Get("https://www.keylala.cn")


ctx = client.WithBody(map[string]interface{}{
    "id": "123456",
    "name": "zero",
}).Post("https://www.keylala.cn")


// 指定 Content-Type 格式,默认 application/x-www-form-urlencoded
ctx = client.WithBody(map[string]interface{}{
    "id": "123456",
    "name": "zero",
}).WithContextTypeJSON().Post("https://www.keylala.cn")

设置超时

默认连接超时时间 2 秒,每次调用超时时间 5 秒

client := zerohttpclient.NewClient().WithDialTimeout(time.Second * time.Duration(1)).WithTimeout(time.Second * time.Duration(2))
ctx := client.Get("https://www.keylala.cn")

# Functions

Connect .
Delete .
Get .
NewClient .
Options .
Patch .
Post
Post .
Put .
Trace .
WithBody 设置 body,interface{} 可以设置为 string 或者 []string 也可以替换为 int8, []int8 等其它基础类型.
WithCache 设置缓存开关.
WithCacheTTL 设置缓存时长.
WithContextTypeJSON 设置 Context-Type 格式.
WithContextTypeURLEncoded 设置 Context-Type 格式.
WithCookie 设置本次调用的 cookie.
WithDebug 设置调试开关.
WithDefaultCache 设置全局缓存开关.
WithDefaultHeaders 设置默认消息头.
WithDialTimeout 设置拨号的超时时间.
WithHeader 设置本次调用的消息头.
WithHeaders 设置本次调用的消息头.
WithLock 手动加锁,会在调用结束时自动解锁.
WithLogger 设置日志.
WithParams 设置 params.
WithProxy 设置代理地址.
WithSign 自动签名中间件,自动添加 timestamp, nonce, sign 值 secret: 签名使用,签名方式见 github.com/zerogo-hub/zero-api-middleware/sign zerohttpclient.WithSign(client, "secret").
WithTimeout 设置每次调用的超时时间.

# Variables

DefaultClient 默认全局对象.

# Structs

Context 一次调用过程的上下文.
HTTPClient 封装客户端,可以使用该客户端重复调用.

# Type aliases

AfterHandler 执行后中间件.
BeforeHandler 执行前中间件.
No description provided by the author