Documentation ¶
Index ¶
- Variables
- func InitH2CClient(rwTimeout time.Duration, connectTimeout ...time.Duration)
- func InitHTTPClient(rwTimeout time.Duration, connectTimeout ...time.Duration)
- func InstallMiddleware(handle ...Handler)
- func SetH2CClient(client Client)
- func SetHTTPClient(client Client)
- type Client
- type ClientImpl
- type HTTPTraceInfo
- type Handler
- type Middleware
- type Request
- type Response
Constants ¶
This section is empty.
Variables ¶
var ErrDefaultMiddleware = errors.New("middleware stop")
ErrDefaultMiddleware The middleware stops and the request returns the default error.
var Marshal func(v interface{}) ([]byte, error)
Marshal Serialization, the default official JSON processor.
var Unmarshal func(data []byte, v interface{}) error
Unmarshal Deserialization, default to the official JSON processor.
Functions ¶
func InitH2CClient ¶
InitH2CClient Initialize H2C client. The parameter rwTimeout is io timeout. The parameter connectTimeout is connect timeout.
func InitHTTPClient ¶
InitHTTPClient Initialize HTTP client. The parameter rwTimeout is io timeout. The parameter connectTimeout is connect timeout.
func InstallMiddleware ¶
func InstallMiddleware(handle ...Handler)
InstallMiddleware Install the middleware processor.
Types ¶
type ClientImpl ¶
ClientImpl The implementation of the client interface.
func NewH2CClient ¶
func NewH2CClient(rwTimeout time.Duration, connectTimeout time.Duration) *ClientImpl
NewH2CClient . The parameter rwTimeout is io timeout. The parameter connectTimeout is connect timeout.
func NewHTTPClient ¶
func NewHTTPClient(rwTimeout time.Duration, connectTimeout time.Duration) *ClientImpl
NewHTTPClient . The parameter rwTimeout is io timeout. The parameter connectTimeout is connect timeout.
type HTTPTraceInfo ¶
type HTTPTraceInfo struct { DNSLookup time.Duration ConnTime time.Duration TCPConnTime time.Duration TLSHandshake time.Duration ServerTime time.Duration ResponseTime time.Duration TotalTime time.Duration IsConnReused bool IsConnWasIdle bool ConnIdleTime time.Duration }
HTTPTraceInfo Link information for the connection.
type Middleware ¶
type Middleware interface { //Go on. Next() Stop(...error) // Returns the standard request object. GetRequest() *http.Request // Returns carry information for HTTP requests. GetRespone() *Response // Returns http package data. GetResponeBody() []byte IsStopped() bool // Is HTTP/2 Cleartext Request. IsH2C() bool Context() context.Context WithContextFromMiddleware(context.Context) // Turn on link tracking for HTTP connections. EnableTraceFromMiddleware() // Set up client. SetClientFromMiddleware(Client) }
Middleware The interface definition of the middleware.
type Request ¶
type Request interface { // HTTP POST method. Post() Request // HTTP PUT method. Put() Request // HTTP GET method. Get() Request // HTTP DELETE method. Delete() Request // HTTP HEAD method. Head() Request // HTTP OPTIONS method. Options() Request // Set up JSON data. SetJSONBody(obj interface{}) Request // Set the original data. SetBody(byts []byte) Request // Set up Form data. SetFormBody(url.Values) Request // Set up File data. SetFile(field, file string) Request // The data is returned after the request and converted to JSON data. ToJSON(obj interface{}) *Response // The data is returned after the request and converted into a string. ToString() (string, *Response) // The data is returned after the request and converted into a []byte. ToBytes() ([]byte, *Response) // The data is returned after the request and converted to XML data. ToXML(v interface{}) *Response // Set the request parameters. SetQueryParam(key string, value interface{}) Request // Set the request parameters. SetQueryParams(map[string]interface{}) Request URL() string Context() context.Context WithContext(context.Context) Request // idempotent request processing, need to fill in KEY. Singleflight(key ...interface{}) Request // Set up HTTP Header information. SetHeader(header http.Header) Request // Add HTTP Header information. AddHeader(key, value string) Request // Returns the header of the current request. Header() http.Header // Returns the Request of the standard library. GetStdRequest() *http.Request // Add cookie information. AddCookie(*http.Cookie) Request // Turn on link tracking. EnableTrace() Request // Set up client. SetClient(client Client) Request }
Request The interface definition of the HTTP request package.
func NewH2CRequest ¶
NewH2CRequest Create an HTTP H2C request object. The URL of the incoming HTTP.
func NewHTTPRequest ¶
NewHTTPRequest Create an HTTP request object. The URL of the incoming HTTP.
type Response ¶
type Response struct { Error error HTTP11 bool ContentType string Status string // e.g. "200 OK" StatusCode int // e.g. 200 Proto string // e.g. "HTTP/1.0" ProtoMajor int // e.g. 1 ProtoMinor int // e.g. 0 Header http.Header ContentLength int64 Uncompressed bool // contains filtered or unexported fields }
Response is a return carry information for HTTP requests.
func (*Response) Cookie ¶
Cookie returns cookie's value by its name returns empty string if nothing was found.
func (*Response) ProtoAtLeast ¶
ProtoAtLeast reports whether the HTTP protocol used in the response is at least major.minor.
func (*Response) TraceInfo ¶
func (res *Response) TraceInfo() HTTPTraceInfo
TraceInfo Link information for the connection.