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 ¶ added in v1.8.8
InitH2CClient Initialize H2C client. The parameter rwTimeout is io timeout. The parameter connectTimeout is connect timeout.
func InitHTTPClient ¶ added in v1.8.0
InitHTTPClient Initialize HTTP client. The parameter rwTimeout is io timeout. The parameter connectTimeout is connect timeout.
func InstallMiddleware ¶ added in v1.8.4
func InstallMiddleware(handle ...Handler)
InstallMiddleware Install the middleware processor.
func SetH2CClient ¶ added in v1.8.8
func SetH2CClient(client Client)
SetH2CClient Set up H2C client.
Types ¶
type ClientImpl ¶ added in v1.8.8
ClientImpl The implementation of the client interface.
func NewH2CClient ¶ added in v1.8.8
func NewH2CClient(rwTimeout time.Duration, connectTimeout time.Duration) *ClientImpl
NewH2CClient . The parameter rwTimeout is io timeout. The parameter connectTimeout is connect timeout.
func NewHTTPClient ¶ added in v1.8.8
func NewHTTPClient(rwTimeout time.Duration, connectTimeout time.Duration) *ClientImpl
NewHTTPClient . The parameter rwTimeout is io timeout. The parameter connectTimeout is connect timeout.
type HTTPTraceInfo ¶ added in v1.8.1
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
// Set up HTTP Header value.
SetHeaderValue(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 ¶ added in v1.8.0
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 ¶ added in v1.8.9
Cookie returns cookie's value by its name returns empty string if nothing was found.
func (*Response) Cookies ¶ added in v1.8.1
Cookies parses and returns the cookies set in the Set-Cookie headers.
func (*Response) ProtoAtLeast ¶ added in v1.8.1
ProtoAtLeast reports whether the HTTP protocol used in the response is at least major.minor.
func (*Response) TraceInfo ¶ added in v1.8.1
func (res *Response) TraceInfo() HTTPTraceInfo
TraceInfo Link information for the connection.