ghttp

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultDialer
	DefaultDialer = &net.Dialer{Timeout: 2000 * time.Millisecond}
	// DefaultTransport
	DefaultTransport http.RoundTripper = &http.Transport{Dial: DefaultDialer.Dial, Proxy: http.ProxyFromEnvironment}
	// DefaultClient
	DefaultClient = &http.Client{Transport: DefaultTransport}
)

Functions

func Deflate

func Deflate() *compression

Deflate

func GetTlsConfig

func GetTlsConfig(cerPath, keyPath string) *tls.Config

GetTlsConfig 生成tls config

func Gzip

func Gzip() *compression

Gzip

func SetConnectTimeout

func SetConnectTimeout(duration time.Duration)

SetConnectTimeout

func Zlib

func Zlib() *compression

Zlib

Types

type Body

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

Body

func (*Body) Close

func (b *Body) Close() error

Close

func (*Body) FromToJson

func (b *Body) FromToJson(o interface{}) error

FromToJson

func (*Body) FromToString

func (b *Body) FromToString() (string, error)

FromToString

func (*Body) Read

func (b *Body) Read(p []byte) (int, error)

Read

type Error

type Error struct {
	Err error
	// contains filtered or unexported fields
}

Error

func (*Error) Error

func (e *Error) Error() string

Error

func (*Error) Timeout

func (e *Error) Timeout() bool

Timeout

type Request

type Request struct {
	Method string
	Url    string
	Body   interface{}
	Query  interface{}

	Timeout           time.Duration
	ContentType       string
	XForwardedFor     string
	Accept            string
	UserAgent         string
	Host              string
	Insecure          bool
	TlsConfig         *tls.Config
	MaxRedirects      int
	RedirectHeaders   bool
	Proxy             string
	Compression       *compression
	BasicAuthUsername string
	BasicAuthPassword string
	CookieJar         http.CookieJar
	ShowDebug         bool
	OnBeforeRequest   func(goxhttp *Request, httpreq *http.Request)
	// contains filtered or unexported fields
}

Request ghttp request lib

func (*Request) AddCookie

func (r *Request) AddCookie(c *http.Cookie)

AddCookie

func (*Request) AddHeader

func (r *Request) AddHeader(key string, value string)

AddHeader

func (Request) Do

func (r Request) Do() (*Response, error)

Do Initiate a request

func (Request) NewRequest

func (r Request) NewRequest() (*http.Request, error)

NewRequest new request before do()

func (Request) WithCookie

func (r Request) WithCookie(c *http.Cookie) Request

WithCookie

func (Request) WithHeader

func (r Request) WithHeader(key string, value string) Request

WithHeader

type Response

type Response struct {
	*http.Response
	Url  string
	Body *Body
	// contains filtered or unexported fields
}

Response ghttp response

func (Response) CancelRequest

func (r Response) CancelRequest()

CancelRequest cancel like postman

Jump to

Keyboard shortcuts

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