request

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	HeaderXForwardedProto    = "X-Forwarded-Proto"
	HeaderXForwardedProtocol = "X-Forwarded-Protocol"
	HeaderXForwardedSsl      = "X-Forwarded-Ssl"
	HeaderXUrlScheme         = "X-Url-Scheme"
)
View Source
const Charset = "UTF-8"
View Source
const OAuthSignatureName = "oauth_signature"

Variables

This section is empty.

Functions

func Address

func Address(req *http.Request) (url string)

func FormatContentTypeAndCharset added in v0.0.2

func FormatContentTypeAndCharset(contentType string, charset ...string) string

func Get

func Get(url string, reply interface{}) (err error)

func HMACSHA1

func HMACSHA1(key, data string) string

func HMACSHA256 added in v1.2.0

func HMACSHA256(key, data string) string

func Post

func Post(url string, data interface{}, reply interface{}) (err error)

func Protocol

func Protocol(req *http.Request) string

func Request

func Request(method, url string, data interface{}, headers ...map[string]string) (reply []byte, err error)

Types

type Client

type Client struct {
	Binder binder.Binder
	// contains filtered or unexported fields
}

Client HTTP 客户端 支持中间件链、OAuth 签名、自动 Content-Type 协商

func New

func New() *Client

func (*Client) Get

func (c *Client) Get(url string, reply interface{}) (err error)

Get 发送 GET 请求并自动解码响应 reply 类型:*[]byte 原始字节、*string 字符串、其他类型走 Binder 反序列化

func (*Client) Marshal added in v1.3.0

func (c *Client) Marshal(data any) (b *bytes.Buffer, err error)

Marshal 将数据序列化为 bytes.Buffer 优先处理 []byte / string / io.Reader 零拷贝路径,其余走 Binder 编码

func (*Client) OAuth added in v1.2.0

func (c *Client) OAuth(key, secret string, strict ...bool) *OAuth

OAuth 初始化 OAuth1 签名器

func (*Client) Post

func (c *Client) Post(url string, data interface{}, reply interface{}) (err error)

Post 发送 POST 请求并自动解码响应

func (*Client) Request

func (c *Client) Request(method, url string, data any, header ...map[string]string) (reply []byte, err error)

Request 执行 HTTP 请求 流程:Marshal → NewRequest → 设置 Header → 中间件链 → OAuth 签名 → 发送 → 读响应

func (*Client) Use

func (c *Client) Use(m middleware)

Use 注册请求前中间件(按注册顺序执行)

func (*Client) Verify added in v1.2.0

func (c *Client) Verify(req *http.Request, body *bytes.Buffer) (err error)

Verify 服务端验证请求的 OAuth 签名

type Header interface {
	Get(key string) string
}

type OAuth

type OAuth struct {
	Strict  bool  //严格模式,body会参与签名
	Timeout int32 //超时秒
	// contains filtered or unexported fields
}

func NewOAuth

func NewOAuth(key, secret string, strict ...bool) *OAuth

func (*OAuth) NewOAuthParams

func (this *OAuth) NewOAuthParams() map[string]string

func (*OAuth) Request added in v1.1.0

func (this *OAuth) Request(req *http.Request) (err error)

Request 自动设置HTTP请求头

func (*OAuth) Signature

func (this *OAuth) Signature(address string, oauth map[string]string, body string) string

Signature 签名Signature method GET POST body JSON字符串

func (*OAuth) Verify

func (this *OAuth) Verify(req *http.Request, body *bytes.Buffer) (err error)

Verify http(s)验签

Jump to

Keyboard shortcuts

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