httpclient

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package httpclient http客户端

Package httpclient is a generated protocol buffer package.

It is generated from these files:

httpclient/test.proto

It has these top-level messages:

Message

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnableMetric added in v1.4.0

func EnableMetric(m *Metric)

EnableMetric 启用metrics

Types

type DNSResolverFunc added in v1.0.8

type DNSResolverFunc func(host string) (ip string, err error)

DNSResolverFunc DNS解析

type DialContext added in v1.0.7

type DialContext func(ctx context.Context, network, addr string) (net.Conn, error)

type FormatUrl added in v1.3.9

type FormatUrl func(u *url.URL)

type Message added in v1.1.3

type Message struct {
	Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
}

func (*Message) Descriptor added in v1.1.3

func (*Message) Descriptor() ([]byte, []int)

func (*Message) GetName added in v1.1.3

func (m *Message) GetName() string

func (*Message) ProtoMessage added in v1.1.3

func (*Message) ProtoMessage()

func (*Message) Reset added in v1.1.3

func (m *Message) Reset()

func (*Message) String added in v1.1.3

func (m *Message) String() string

type Metric added in v1.3.9

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

Metric 统计

func NewMetric added in v1.3.9

func NewMetric(namespace, subsystem string, formatUrl FormatUrl) *Metric

func (*Metric) Count added in v1.3.9

func (m *Metric) Count(url *url.URL, err error)

func (*Metric) Latency added in v1.3.9

func (m *Metric) Latency(url *url.URL, d time.Duration)

type Option added in v1.0.6

type Option func(*options)

func WithClient added in v1.0.6

func WithClient(client *http.Client) Option

WithClient 自定义http client

func WithClientTrace added in v1.1.3

func WithClientTrace(t *httptrace.ClientTrace) Option

func WithConnectTimeout added in v1.0.9

func WithConnectTimeout(timeout time.Duration) Option

WithConnectTimeout 设置连接超时

func WithCookieJar added in v1.1.0

func WithCookieJar(cookieJar http.CookieJar) Option

func WithDNSResolver added in v1.0.7

func WithDNSResolver(dnsResolver DNSResolverFunc) Option

func WithDebug added in v1.0.6

func WithDebug() Option

WithDebug 开启调试模式

func WithDisableKeepAlive added in v1.0.6

func WithDisableKeepAlive() Option

WithDisableKeepAlive 连接重用

func WithEnableDefaultHeader added in v1.0.6

func WithEnableDefaultHeader() Option

WithEnableDefaultHeader 设置默认header

func WithMaxIdleConnsPerHost added in v1.0.9

func WithMaxIdleConnsPerHost(n int) Option

WithMaxIdleConnsPerHost 设置每个host最大空闲连接数

func WithProxyURL added in v1.0.6

func WithProxyURL(proxyURL string) Option

WithProxyURL 设置代理

func WithRequestInterceptor added in v1.1.3

func WithRequestInterceptor(i RequestInterceptor) Option

func WithResponseInterceptor added in v1.1.3

func WithResponseInterceptor(i ResponseInterceptor) Option

func WithRetryTime added in v1.0.6

func WithRetryTime(retryTimes int) Option

WithRetryTime 设置重试次数

func WithShouldRetryFunc added in v1.0.6

func WithShouldRetryFunc(f func(*http.Request, *http.Response, error) bool) Option

WithShouldRetryFunc 自定义是否需要重试

func WithTimeout added in v1.0.6

func WithTimeout(timeout time.Duration) Option

WithTimeout 设置超时

func WithUnixSocketPath added in v1.2.8

func WithUnixSocketPath(path string) Option

type Request

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

Request http请求

func NewRequest

func NewRequest(opt ...Option) *Request

NewRequest 创建request

func (*Request) Delete added in v1.1.7

func (req *Request) Delete(url string, data interface{}, header http.Header) (*Response, error)

Delete Delete请求

func (*Request) Do added in v1.4.1

func (req *Request) Do(ctx context.Context, method string, url string, data interface{}, header http.Header) (*Response, error)

func (*Request) Get

func (req *Request) Get(url string, params url.Values, header http.Header) (*Response, error)

Get get请求

func (*Request) Post

func (req *Request) Post(url string, data interface{}, header http.Header) (*Response, error)

Post 普通post请求

func (*Request) PostJSON

func (req *Request) PostJSON(url string, data interface{}, header http.Header) (*Response, error)

PostJSON 发送json body

func (*Request) PostProtoBuf added in v1.1.3

func (req *Request) PostProtoBuf(url string, v proto.Message, header http.Header) (*Response, error)

PostProtoBuf 发送protoBuf body

func (*Request) Put added in v1.1.7

func (req *Request) Put(url string, data interface{}, header http.Header) (*Response, error)

Put Put请求

func (*Request) UploadFile added in v1.1.8

func (req *Request) UploadFile(url string, reader io.Reader, filename string, header http.Header, params map[string]string) (*Response, error)

UploadFile 上传文件

type RequestInterceptor added in v1.1.3

type RequestInterceptor func(req *http.Request)

type Response

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

Response http响应

func Get

func Get(url string, data url.Values, header http.Header) (*Response, error)

Get get请求

func Post

func Post(url string, data interface{}, header http.Header) (*Response, error)

Post 普通post请求

func PostJSON

func PostJSON(url string, data interface{}, header http.Header) (*Response, error)

PostJSON 发送json body

func (*Response) Bytes

func (resp *Response) Bytes() ([]byte, error)

Bytes 读取http.Body, 返回bytes

func (*Response) DecodeJSON

func (resp *Response) DecodeJSON(v interface{}) error

DecodeJSON json decode

func (*Response) DecodeProtoBuf added in v1.1.3

func (resp *Response) DecodeProtoBuf(v interface{}) error

DecodeProtoBuf protoBuf decode

func (*Response) Discard

func (resp *Response) Discard() (int64, error)

Discard 丢弃http.body

func (*Response) Header

func (resp *Response) Header() http.Header

Header 获取header

func (*Response) IsStatusOK

func (resp *Response) IsStatusOK() bool

IsStatusOK 响应码是否为200

func (*Response) Raw

func (resp *Response) Raw() *http.Response

Raw 获取原始的http response

func (*Response) String

func (resp *Response) String() (string, error)

String 读取http.Body, 返回string

func (*Response) WriteFile

func (resp *Response) WriteFile(filename string) (int64, error)

WriteFile 读取http.Body内容并写入文件中

func (*Response) WriteTo

func (resp *Response) WriteTo(w io.Writer) (int64, error)

WriteTo 读取http.Body并写入w中

type ResponseInterceptor added in v1.1.3

type ResponseInterceptor func(req *http.Request, resp *http.Response, err error)

Jump to

Keyboard shortcuts

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