Documentation ¶
Index ¶
- Constants
- func Compose(ctx Context, middleware []Middleware) func() error
- func RegisterMiddlewareFactory(name string, factory MiddlewareFactory)
- type Body
- type BodyInterface
- type ContentType
- type Context
- type Middleware
- func NewBasicAuthMiddlewareFactory(v ...interface{}) (Middleware, error)
- func NewDebugMiddlewareFactory(v ...interface{}) (Middleware, error)
- func NewMiddleware(name string, v ...interface{}) (Middleware, error)
- func NewRequestExecMiddlewareFactory(v ...interface{}) (Middleware, error)
- func NewTimeMiddlewareFactory(v ...interface{}) (Middleware, error)
- type MiddlewareFactory
- type Next
- type Request
- type Response
- type URL
Constants ¶
const ( Method_GET = "GET" Method_POST = "POST" Method_HEAD = "HEAD" Method_PUT = "PUT" Method_UPDATE = "UPDATE" Method_DELETE = "DELETE" )
Variables ¶
This section is empty.
Functions ¶
func Compose ¶
func Compose(ctx Context, middleware []Middleware) func() error
Composer all middleware Return the start middleware
func RegisterMiddlewareFactory ¶
func RegisterMiddlewareFactory(name string, factory MiddlewareFactory)
Register your middleware to factory pool
Types ¶
type BodyInterface ¶
type ContentType ¶
func ParseContentType ¶
func ParseContentType(raw string) ContentType
func (*ContentType) String ¶
func (c *ContentType) String() string
type Context ¶
type Middleware ¶
func NewBasicAuthMiddlewareFactory ¶
func NewBasicAuthMiddlewareFactory(v ...interface{}) (Middleware, error)
Middleware: HTTP Basic Auth
func NewDebugMiddlewareFactory ¶
func NewDebugMiddlewareFactory(v ...interface{}) (Middleware, error)
Middleware: this middleware allow you to debug request information and response
func NewMiddleware ¶
func NewMiddleware(name string, v ...interface{}) (Middleware, error)
The factory method to create a new middleware tip: you must register your middleware firstly by invoke isuperagent.RegisterMiddleware() method
func NewRequestExecMiddlewareFactory ¶
func NewRequestExecMiddlewareFactory(v ...interface{}) (Middleware, error)
Middleware: send request
The last of middleware chain, it will call after all middleware. This middleware will do the following duties: 1. Generate the request object. 2. Set all request options, include queries, headers, bodies, authorization. 3. Send request, Generate response object. 4. Retry strategy when failure. Then return *Response, error to previous middleware.
func NewTimeMiddlewareFactory ¶
func NewTimeMiddlewareFactory(v ...interface{}) (Middleware, error)
Middleware: record the request duration
type MiddlewareFactory ¶
type MiddlewareFactory func(v ...interface{}) (Middleware, error)
Middleware factory method it is convenient to create an middleware
type Next ¶
type Next func() error
The method to call the next middleware Only middleware call next() method, the next middleware will invoke At last, the request will send to target server
type Request ¶
type Request interface { SetMethod(method string, options ...interface{}) Request GetMethod() string Get(url string, options ...interface{}) Request Post(url string, options ...interface{}) Request Head(url string, options ...interface{}) Request Put(url string, options ...interface{}) Request Update(url string, options ...interface{}) Request Delete(url string, options ...interface{}) Request SetUrl(url string) Request GetUrl() *URL GetRawUrl() string GetHeader(name string) string SetHeader(name, value string) Request GetHeaders() http.Header SetHeaders(kv map[string]string) Request SetContentType(contentType string) Request GetQuery(name string) string SetQuery(name string, value string) Request GetQueries() url.Values SetQueries(kv map[string]string) Request SetBody(v interface{}) Request GetBody() interface{} GetBodyRaw() ([]byte, error) SetTimeout(d time.Duration) Request GetTimeout() time.Duration SetRetry(times int) Request GetRetry() int SetInsecureSkipVerify(insecureSkipVerify bool) Request GetInsecureSkipVerify() bool SetTlsConfig(tlsConfig *tls.Config) Request GetTlsConfig() *tls.Config SetCa(caPath string) Request GetCa() string SetCert(certPath, keyPath string) Request GetCert() (string, string) BasicAuth(name, pass string) Request GetUsername() string GetPassword() string SetContext(ctx context.Context) Request Middleware(middleware ...Middleware) Request Do() (Response, error) }
func NewRequest ¶
func NewRequest() Request