xcli

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: MulanPSL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeJson     = "application/json"
	ContentTypeXml      = "application/xml"
	ContentTypeProtobuf = "application/octet-stream"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyMap

type BodyMap map[string]interface{}

通用请求/响应(不需要结果的)参数 map

func NewBodyMap

func NewBodyMap(size int) BodyMap

func (BodyMap) GetFormatJsonForPrint

func (r BodyMap) GetFormatJsonForPrint() string

获取格式化后的 json, 用于打印

func (BodyMap) Marshal

func (r BodyMap) Marshal() ([]byte, error)

func (BodyMap) Set

func (r BodyMap) Set(key string, value interface{}) BodyMap

func (BodyMap) Unmarshal

func (r BodyMap) Unmarshal(resp []byte) (BodyMap, error)

type HttpCli

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

HttpCli 会自己释放 Response.Body 并发安全由外部控制

func NewHttpCli

func NewHttpCli(opts ...HttpClientOption) *HttpCli

func (*HttpCli) Get

func (h *HttpCli) Get(url string) (*HttpCliResp, error)

func (*HttpCli) GetHeader

func (h *HttpCli) GetHeader(key string) string

func (*HttpCli) HeaderIsExist

func (h *HttpCli) HeaderIsExist(key string) bool

func (*HttpCli) Post

func (h *HttpCli) Post(url string, body []byte, contentType ...string) (*HttpCliResp, error)

请求体为 []byte 数组, 不能打印请求体

func (*HttpCli) PostForHttpCliBodyer

func (h *HttpCli) PostForHttpCliBodyer(url string, body httpCliBodyer) (*HttpCliResp, error)

请求体为 HttpCliBodyer, 支持多种请求协议, 默认按 protobuf 协议处理, 同时可以打印请求体

func (*HttpCli) ReGet

func (h *HttpCli) ReGet(url string, maxCount ...int) (*HttpCliResp, error)

ReGet 重试

func (*HttpCli) SetHeader

func (h *HttpCli) SetHeader(key, value string)

type HttpCliJsonBody

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

json 协议实现 HttpCliBodyer

func NewHttpCliJsonBody

func NewHttpCliJsonBody(body interface{}) *HttpCliJsonBody

type HttpCliResp

type HttpCliResp struct {
	StatusCode int
	Body       []byte
	Header     http.Header
}

func Get

func Get(url string, headers map[string]string) (*HttpCliResp, error)

func Post

func Post(url string, body []byte, headers map[string]string) (*HttpCliResp, error)

请求体为 []byte 数组, 不能打印请求体

func PostForHttpCliBodyer

func PostForHttpCliBodyer(url string, body httpCliBodyer, headers map[string]string) (*HttpCliResp, error)

请求体为 HttpCliBodyer, 支持多种请求协议, 同时可以打印请求体

func (*HttpCliResp) Text

func (h *HttpCliResp) Text() string

type HttpCliXmlBody

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

xml 协议实现 HttpCliBodyer

func NewHttpCliXmlBody

func NewHttpCliXmlBody(body interface{}) *HttpCliXmlBody

type HttpClientOption

type HttpClientOption func(h *HttpCli)

func WithHttpCliTimeOut

func WithHttpCliTimeOut(timeOut time.Duration) HttpClientOption

设置过去时间

func WithPrint

func WithPrint(is bool) HttpClientOption

WithPrint 是否打印 log

func WithProxy

func WithProxy(uri *url.URL) HttpClientOption

WithProxy 设置代理

Jump to

Keyboard shortcuts

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