request

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DialTimeout represents the maximum amount of time the network dialer can take.
	DialTimeout = 30 * time.Second

	// DialKeepAlive represents the maximum amount of time too keep alive the socket.
	DialKeepAlive = 30 * time.Second

	// TLSHandshakeTimeout represents the maximum amount of time that
	// TLS handshake can take defined in the default http.Transport.
	TLSHandshakeTimeout = 10 * time.Second

	// RequestTimeout represents the maximum about of time that
	// a request can take, including dial / request / redirect processes.
	RequestTimeout = 60 * time.Second

	// DefaultDialer defines the default network dialer.
	DefaultDialer = &net.Dialer{
		Timeout:   DialTimeout,
		KeepAlive: DialKeepAlive,
	}
)

Functions

This section is empty.

Types

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

BasicAuth http basic auth with username and password

func (BasicAuth) Apply

func (b BasicAuth) Apply(ctx *context.Context)

Apply http basic auth with username and password

func (BasicAuth) Valid

func (b BasicAuth) Valid() bool

Valid http basic auth with username and password valid?

type BearerAuth

type BearerAuth struct {
	Data string
}

BearerAuth token

func (BearerAuth) Apply

func (b BearerAuth) Apply(ctx *context.Context)

Apply bearer token

func (BearerAuth) Valid

func (b BearerAuth) Valid() bool

Valid bearer token valid?

type BodyForm

type BodyForm struct {
	Fields map[string]string
	Files  []string
}

BodyForm represents the supported form fields by file and string data.

func (BodyForm) Apply

func (fd BodyForm) Apply(ctx *context.Context)

Apply Form Data

func (BodyForm) Valid

func (fd BodyForm) Valid() bool

Valid form body valid?

type BodyJSON

type BodyJSON struct {
	Data interface{}
}

BodyJSON body of type json

func (BodyJSON) Apply

func (b BodyJSON) Apply(ctx *context.Context)

Apply json body

func (BodyJSON) Valid

func (b BodyJSON) Valid() bool

Valid json body valid?

type BodyString

type BodyString struct {
	Data string
}

BodyString body of type string

func (BodyString) Apply

func (b BodyString) Apply(ctx *context.Context)

Apply string body

func (BodyString) Valid

func (b BodyString) Valid() bool

Valid string body valid?

type BodyURLEncodedForm

type BodyURLEncodedForm struct {
	Data interface{}
}

BodyURLEncodedForm application/x-www-form-urlencoded

func (BodyURLEncodedForm) Apply

func (b BodyURLEncodedForm) Apply(ctx *context.Context)

Apply application/x-www-form-urlencoded

func (BodyURLEncodedForm) Valid

func (b BodyURLEncodedForm) Valid() bool

Valid application/x-www-form-urlencoded valid?

type BodyXML

type BodyXML struct {
	Data interface{}
}

BodyXML body of type xml

func (BodyXML) Apply

func (b BodyXML) Apply(ctx *context.Context)

Apply xml body

func (BodyXML) Valid

func (b BodyXML) Valid() bool

Valid xml body valid?

type BodyYAML

type BodyYAML struct {
	Data interface{}
}

BodyYAML body of type yaml

func (BodyYAML) Apply

func (b BodyYAML) Apply(ctx *context.Context)

Apply yaml body

func (BodyYAML) Valid

func (b BodyYAML) Valid() bool

Valid json body valid?

type Cookies

type Cookies struct {
	Data []*http.Cookie
	Map  map[string]string
}

Cookies http cookies

func (Cookies) Apply

func (c Cookies) Apply(ctx *context.Context)

Apply http cookies

func (Cookies) Valid

func (c Cookies) Valid() bool

Valid http cookies valid?

type CustomerAuth

type CustomerAuth struct {
	Data string
}

CustomerAuth customer Authorization on header

func (CustomerAuth) Apply

func (c CustomerAuth) Apply(ctx *context.Context)

Apply customer Authorization on header

func (CustomerAuth) Valid

func (c CustomerAuth) Valid() bool

Valid customer Authorization on header valid?

type FormFile

type FormFile struct {
	Name   string
	Reader io.Reader
}

FormFile represents the file form field data.

type Header struct {
	Data map[string]string
}

Header http header

func (Header) Apply

func (h Header) Apply(ctx *context.Context)

Apply apply http headers

func (Header) Valid

func (h Header) Valid() bool

Valid user agent in header valid?

type Host

type Host struct {
	Data string
}

Host http host name like: https://www.google.com

func (Host) Apply

func (h Host) Apply(ctx *context.Context)

Apply http host name like: https://www.google.com

func (Host) Valid

func (h Host) Valid() bool

Valid http host name like: https://www.google.com valid?

type Method

type Method struct {
	Data string
}

Method http method: GET, POST, DELETE ...

func (Method) Apply

func (m Method) Apply(ctx *context.Context)

Apply http method: GET, POST, DELETE ...

func (Method) Valid

func (m Method) Valid() bool

Valid http method: GET, POST, DELETE ... valid?

type Path

type Path struct {
	Data string
}

Path http url path like: /api/v1/xx

func (Path) Apply

func (p Path) Apply(ctx *context.Context)

Apply http url path like: /api/v1/xx

func (Path) Valid

func (p Path) Valid() bool

Valid http url path like: /api/v1/xx valid?

type Plugin

type Plugin interface {

	// Apply the plugin to http request
	Apply(*context.Context)

	// Valid is the plugin need run?
	Valid() bool
}

Plugin parse user defined request

type Proxy

type Proxy struct {
	Servers map[string]string
	URL     string
}

Proxy http proxy url or multi services

func (Proxy) Apply

func (p Proxy) Apply(ctx *context.Context)

Apply http proxy url or multi services

func (Proxy) Valid

func (p Proxy) Valid() bool

Valid http proxy url or multi services valid?

type Query

type Query struct {
	Data map[string]string
}

Query http query params like: ?a=1&b=2

func (Query) Apply

func (q Query) Apply(ctx *context.Context)

Apply http query params like: ?a=1&b=2

func (Query) Valid

func (q Query) Valid() bool

Valid http url path like: /api/v1/xx valid?

type Request

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

Request an alias of context

func New

func New() *Request

New request struct

func NewWithContext

func NewWithContext(ctx originContext.Context) *Request

NewWithContext request struct

func (*Request) AddBasicAuth

func (r *Request) AddBasicAuth(username, password string) *Request

AddBasicAuth ...

func (*Request) AddBearerAuth

func (r *Request) AddBearerAuth(data string) *Request

AddBearerAuth ...

func (*Request) AddCookiesMap

func (r *Request) AddCookiesMap(data map[string]string) *Request

AddCookiesMap ...

func (*Request) AddHeader

func (r *Request) AddHeader(data map[string]string) *Request

AddHeader ...

func (*Request) AddJSON

func (r *Request) AddJSON(data interface{}) *Request

AddJSON ...

func (*Request) AddMultipartForm

func (r *Request) AddMultipartForm(fields map[string]string, files []string) *Request

AddMultipartForm ...

func (*Request) AddQuery

func (r *Request) AddQuery(data map[string]string) *Request

AddQuery ...

func (*Request) AddSortedHeader

func (r *Request) AddSortedHeader(data [][2]string) *Request

AddSortedHeader ...

func (*Request) AddTLSConfig

func (r *Request) AddTLSConfig(data *tls.Config) *Request

AddTLSConfig ...

func (*Request) AddTransform

func (r *Request) AddTransform(data http.RoundTripper) *Request

AddTransform ...

func (*Request) AddURLEncodedForm

func (r *Request) AddURLEncodedForm(data interface{}) *Request

AddURLEncodedForm ...

func (*Request) AddXML

func (r *Request) AddXML(data interface{}) *Request

AddXML ...

func (*Request) AddYAML

func (r *Request) AddYAML(data interface{}) *Request

AddYAML ...

func (*Request) Ctx

func (r *Request) Ctx() *context.Context

Ctx get request ctx

func (*Request) DELETE

func (r *Request) DELETE(url string) *Request

DELETE use DELETE method and http url

func (*Request) Error

func (r *Request) Error() error

Error get request error

func (*Request) GET

func (r *Request) GET(url string) *Request

GET use GET method and http url

func (*Request) HEAD

func (r *Request) HEAD(url string) *Request

HEAD use HEAD method and http url

func (*Request) OPTIONS

func (r *Request) OPTIONS(url string) *Request

OPTIONS use OPTIONS method and http url

func (*Request) PATCH

func (r *Request) PATCH(url string) *Request

PATCH use PATCH method and http url

func (*Request) POST

func (r *Request) POST(url string) *Request

POST use POST method and http url

func (*Request) PUT

func (r *Request) PUT(url string) *Request

PUT use PUT method and http url

func (*Request) Send

func (r *Request) Send() *response.Sugar

Send ...

func (*Request) TRACE

func (r *Request) TRACE(url string) *Request

TRACE use TRACE method and http url

type SortedHeader

type SortedHeader struct {
	Data [][2]string
}

SortedHeader header slice, example [][2]string{{k1,v1},{k2,v2}}

func (SortedHeader) Apply

func (h SortedHeader) Apply(ctx *context.Context)

Apply apply http headers

func (SortedHeader) Valid

func (h SortedHeader) Valid() bool

Valid user agent in header valid?

type TLSConfig

type TLSConfig struct {
	*tls.Config
}

TLSConfig http tls config of transport

func (TLSConfig) Apply

func (tc TLSConfig) Apply(ctx *context.Context)

Apply http tls config of transport

func (TLSConfig) Valid

func (tc TLSConfig) Valid() bool

Valid http timeouts of tls, dial, keepalive or all valid?

type Timeouts

type Timeouts struct {
	// Request represents the total timeout including dial / request / redirect steps
	Request time.Duration

	// TLS represents the maximum amount of time for TLS handshake process
	TLS time.Duration

	// Dial represents the maximum amount of time for dialing process
	Dial time.Duration

	// KeepAlive represents the maximum amount of time to keep alive the socket
	KeepAlive time.Duration
}

Timeouts represents the supported timeouts

func (Timeouts) Apply

func (to Timeouts) Apply(ctx *context.Context)

Apply http timeouts of tls, dial, keepalive or all

func (Timeouts) Valid

func (to Timeouts) Valid() bool

Valid http timeouts of tls, dial, keepalive or all valid?

type Transport

type Transport struct {
	http.RoundTripper
}

Transport http Transport

func (Transport) Apply

func (t Transport) Apply(ctx *context.Context)

Apply http Transport

func (Transport) Valid

func (t Transport) Valid() bool

Valid http timeouts of tls, dial, keepalive or all valid?

type URL

type URL struct {
	Data string
}

URL http url (host+path+params)

func (URL) Apply

func (_u URL) Apply(ctx *context.Context)

Apply http url (host+path+params)

func (URL) Valid

func (_u URL) Valid() bool

Valid http url path like: /api/v1/xx valid?

type UserAgent

type UserAgent struct {
	Version string
}

UserAgent user agent in header

func (UserAgent) Apply

func (ua UserAgent) Apply(ctx *context.Context)

Apply user agent in header

func (UserAgent) Valid

func (ua UserAgent) Valid() bool

Valid user agent in header valid?

Jump to

Keyboard shortcuts

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