restc

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: Apache-2.0 Imports: 23 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.

Types

type Cfg

type Cfg struct {
	Token                         string
	KeepAlive                     bool
	Timeout                       time.Duration
	RetryCount                    uint32
	Name                          string
	NoDefaultUserAgentHeader      bool
	DialDualStack                 bool
	MaxConnsPerHost               int
	MaxIdleConnDuration           time.Duration
	MaxConnDuration               time.Duration
	MaxIdemponentCallAttempts     int
	ReadBufferSize                int
	WriteBufferSize               int
	ReadTimeout                   time.Duration
	WriteTimeout                  time.Duration
	MaxResponseBodySize           int
	DisableHeaderNamesNormalizing bool
	DisablePathNormalizing        bool
	MaxConnWaitTimeout            time.Duration
	Proxy                         bool
	Socks5                        string
	CertPath                      string
	KeyPath                       string
	Insecure                      bool
	Header                        map[string]string

	Middlewares []types.Middleware
	// 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 *Request) (*http.Response, error)
	Get(ctx context.Context, url string, requests ...func(req *Request)) (*http.Response, error)
	Delete(ctx context.Context, url string, data interface{}, requests ...func(req *Request)) (*http.Response, error)
	Post(ctx context.Context, url string, data interface{}, requests ...func(req *Request)) (*http.Response, error)
	PostForm(ctx context.Context, url string, val url.Values, requests ...func(req *Request)) (*http.Response, error)
	Put(ctx context.Context, url string, data interface{}, requests ...func(req *Request)) (*http.Response, error)
	Patch(ctx context.Context, url string, data interface{}, requests ...func(req *Request)) (*http.Response, error)
}

Client http clientImpl interface

type DebugRequestTransport

type DebugRequestTransport struct {
	RequestHeader  bool
	RequestBody    bool // RequestHeader 为 true 时,这个选项才会生效
	ResponseHeader bool
	ResponseBody   bool // ResponseHeader 为 true 时,这个选项才会生效

	// debug 信息输出到 Writer 中, 默认是 os.Stderr
	Writer io.Writer

	Transport http.RoundTripper
}

DebugRequestTransport 会打印请求和响应信息, 方便调试.

func (*DebugRequestTransport) RoundTrip

func (t *DebugRequestTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface.

type Request

type Request struct {
	*http.Request
	// contains filtered or unexported fields
}

func (*Request) Client added in v0.1.18

func (r *Request) Client() bool

func (*Request) Codec added in v0.1.18

func (r *Request) Codec() encoding.Codec

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() types.Header

func (*Request) Kind added in v0.1.18

func (r *Request) Kind() string

func (*Request) Method added in v0.1.18

func (r *Request) Method() string

func (*Request) Payload added in v0.1.18

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

func (*Request) Read added in v0.1.18

func (r *Request) Read() ([]byte, error)

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 = http.Response

func Delete

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

func Do

func Do(ctx context.Context, req *Request) (*Response, error)

func Get

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

func Patch

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

func Post

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

func PostForm

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

func Put

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

type Uploader

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

func NewUploader

func NewUploader(c Client) *Uploader

func (*Uploader) AddFile

func (u *Uploader) AddFile(formname, filename string, fileReader io.Reader) *Uploader

func (*Uploader) AddParam

func (u *Uploader) AddParam(name, value string) *Uploader

func (*Uploader) AddParams

func (u *Uploader) AddParams(params map[string][]string) *Uploader

func (*Uploader) Body

func (u *Uploader) Body() (io.Reader, error)

func (*Uploader) ContentType

func (u *Uploader) ContentType() string

func (*Uploader) SetBoundary

func (u *Uploader) SetBoundary(boundary string) *Uploader

func (*Uploader) SetParams

func (u *Uploader) SetParams(params map[string][]string) *Uploader

Jump to

Keyboard shortcuts

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