restc

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const Name = "restc"

Variables

This section is empty.

Functions

func DefaultClient

func DefaultClient() *http.Client

DefaultClient returns a new http.Client with similar default values to http.Client, but with a non-shared Transport, idle connections disabled, and keepalives disabled.

func DefaultPooledClient

func DefaultPooledClient() *http.Client

DefaultPooledClient returns a new http.Client with similar default values to http.Client, but with a shared Transport. Do not use this function for transient clients as it can leak file descriptors over time. Only use this for clients that will be re-used for the same host(s).

func DefaultPooledTransport

func DefaultPooledTransport() *http.Transport

DefaultPooledTransport returns a new http.Transport with similar default values to http.DefaultTransport. Do not use this for transient transports as it can leak file descriptors over time. Only use this for transports that will be re-used for the same host(s).

func DefaultTransport

func DefaultTransport() *http.Transport

DefaultTransport returns a new http.Transport with similar default values to http.DefaultTransport, but with idle connections and keepalives disabled.

func Delete

func Delete(ctx context.Context, url string, requests ...func(req *fasthttp.Request)) (*fasthttp.Response, error)

func Do

func Get

func Get(ctx context.Context, url string, requests ...func(req *fasthttp.Request)) (*fasthttp.Response, error)

func Patch

func Patch(ctx context.Context, url string, data interface{}, requests ...func(req *fasthttp.Request)) (*fasthttp.Response, error)

func Post

func Post(ctx context.Context, url string, data interface{}, requests ...func(req *fasthttp.Request)) (*fasthttp.Response, error)

func PostForm

func PostForm(ctx context.Context, url string, val url.Values, requests ...func(req *fasthttp.Request)) (*fasthttp.Response, error)

func Put

func Put(ctx context.Context, url string, data interface{}, requests ...func(req *fasthttp.Request)) (*fasthttp.Response, error)

Types

type Cfg

type Cfg struct {
	Trace       bool              `yaml:"trace"`
	Token       string            `yaml:"token"`
	Timeout     time.Duration     `yaml:"timeout"`
	RetryCount  uint32            `yaml:"retry-count"`
	Proxy       bool              `yaml:"proxy"`
	Socks5      string            `yaml:"socks5"`
	Insecure    bool              `yaml:"insecure"`
	Header      map[string]string `yaml:"header"`
	Middlewares []string          `yaml:"middlewares"`
	BasePath    string            `yaml:"base-path"`
	// contains filtered or unexported fields
}

func DefaultCfg

func DefaultCfg() *Cfg

func (*Cfg) Build

func (t *Cfg) Build(opts ...func(cfg *Cfg)) (_ Client, err error)

type Client

type Client interface {
	Do(ctx context.Context, req *fasthttp.Request) (*fasthttp.Response, error)
	Head(ctx context.Context, url string, opts ...func(req *fasthttp.Request)) (*fasthttp.Response, error)
	Get(ctx context.Context, url string, opts ...func(req *fasthttp.Request)) (*fasthttp.Response, error)
	Delete(ctx context.Context, url string, opts ...func(req *fasthttp.Request)) (*fasthttp.Response, error)
	Post(ctx context.Context, url string, data interface{}, opts ...func(req *fasthttp.Request)) (*fasthttp.Response, error)
	PostForm(ctx context.Context, url string, val url.Values, opts ...func(req *fasthttp.Request)) (*fasthttp.Response, error)
	Put(ctx context.Context, url string, data interface{}, opts ...func(req *fasthttp.Request)) (*fasthttp.Response, error)
	Patch(ctx context.Context, url string, data interface{}, opts ...func(req *fasthttp.Request)) (*fasthttp.Response, error)
}

Client http clientImpl interface

type Request

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

func (*Request) Client added in v0.1.18

func (r *Request) Client() bool

func (*Request) ContentType added in v0.1.18

func (r *Request) ContentType() string

func (*Request) Endpoint added in v0.1.18

func (r *Request) Endpoint() string

func (*Request) Header added in v0.1.18

func (r *Request) Header() *service.RequestHeader

func (*Request) Kind added in v0.1.18

func (r *Request) Kind() string

func (*Request) Operation added in v0.1.26

func (r *Request) Operation() string

func (*Request) Payload added in v0.1.18

func (r *Request) Payload() interface{}

func (*Request) Service added in v0.1.18

func (r *Request) Service() string

func (*Request) Stream added in v0.1.18

func (r *Request) Stream() bool

type Response

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

func (*Response) Header added in v0.1.26

func (r *Response) Header() *service.ResponseHeader

func (*Response) Payload added in v0.1.26

func (r *Response) Payload() interface{}

func (*Response) Stream added in v0.1.26

func (r *Response) Stream() bool

type TraceInfo added in v0.1.26

type TraceInfo struct {
	// DNSLookup is a duration that transport took to perform
	// DNS lookup.
	DNSLookup time.Duration

	// ConnTime is a duration that took to obtain a successful connection.
	ConnTime time.Duration

	// TCPConnTime is a duration that took to obtain the TCP connection.
	TCPConnTime time.Duration

	// TLSHandshake is a duration that TLS handshake took place.
	TLSHandshake time.Duration

	// ServerTime is a duration that server took to respond first byte.
	ServerTime time.Duration

	// ResponseTime is a duration since first Response byte from server to
	// request completion.
	ResponseTime time.Duration

	// TotalTime is a duration that total request took end-to-end.
	TotalTime time.Duration

	// IsConnReused is whether this connection has been previously
	// used for another HTTP request.
	IsConnReused bool

	// IsConnWasIdle is whether this connection was obtained from an
	// idle pool.
	IsConnWasIdle bool

	// ConnIdleTime is a duration how long the connection was previously
	// idle, if IsConnWasIdle is true.
	ConnIdleTime time.Duration

	// RequestAttempt is to represent the request attempt made during a Resty
	// request execution flow, including retry count.
	RequestAttempt uint32

	// RemoteAddr returns the remote network address.
	RemoteAddr net.Addr
}

TraceInfo struct is used provide request trace info such as DNS lookup duration, Connection obtain duration, Server processing duration, etc.

Since v2.0.0

Jump to

Keyboard shortcuts

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