Documentation
¶
Index ¶
- Constants
- func Get(addr, path string) (*fasthttp.Response, error)
- func ListenAndServe(addr string, handler fasthttp.RequestHandler) error
- func MarshalRequest(req *fasthttp.Request) ([]byte, error)
- func MarshalResponse(resp *fasthttp.Response) ([]byte, error)
- func UnmarshalRequest(frame []byte, dst *fasthttp.Request) error
- func UnmarshalResponse(frame []byte, dst *fasthttp.Response) error
- type Server
- type Transport
Constants ¶
const ( FrameRequest uint16 = 0x01 FrameResponse uint16 = 0x02 )
Frame type IDs. The ZAP message header carries the type in the upper byte of the 16-bit flags field; FinishWithFlags(t<<8) tags the message and Message.Flags()>>8 recovers it. A request frame and a response frame are the two shapes the wire carries today.
const MaxFrameSize = 64 << 20 // 64 MiB
MaxFrameSize bounds an inbound frame. The wire format leaves room for larger frames; the limit here defends a server against a malicious peer announcing a multi-gigabyte length prefix.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
Get is a convenience for one-shot service-to-service calls. The caller owns resp and must fasthttp.ReleaseResponse it when done.
func ListenAndServe ¶
func ListenAndServe(addr string, handler fasthttp.RequestHandler) error
ListenAndServe is the convenience equivalent of fasthttp.ListenAndServe.
func MarshalRequest ¶
MarshalRequest serializes a *fasthttp.Request into a ZAP frame. The returned bytes are the ZAP message; the transport layer prepends the length prefix (see transport.go).
func MarshalResponse ¶
MarshalResponse serializes a *fasthttp.Response into a ZAP frame.
func UnmarshalRequest ¶
UnmarshalRequest reconstructs a request into dst from a ZAP frame. dst is reset first, then populated: method, request-URI, protocol, headers, trailers, and body. Content-Length is derived from the body length by SetBody; Host is taken from a Host header if the frame carried one.
Types ¶
type Server ¶
type Server struct {
Addr string // ":9999" if empty
Handler fasthttp.RequestHandler // required
ReadTimeout time.Duration // 0 means no timeout
WriteTimeout time.Duration
IdleTimeout time.Duration
Logger fasthttp.Logger // passed to each RequestCtx; nil is fine
// contains filtered or unexported fields
}
Server is a ZAP-HTTP server. Zero-value is usable; common knobs (Addr, Handler, ReadTimeout, …) mirror fasthttp.Server.
func (*Server) ListenAndServe ¶
ListenAndServe binds Addr and serves until Close is called or a fatal accept error occurs.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport speaks ZAP-HTTP over a pooled TCP connection. Field-zero is invalid; use NewTransport.
func NewTransport ¶
NewTransport returns a Transport connecting to the given host:port.
func (*Transport) CloseIdleConnections ¶
func (t *Transport) CloseIdleConnections()
CloseIdleConnections closes every idle conn in the pool. Active requests are unaffected. Useful in tests and on shutdown.
func (*Transport) Do ¶
Do executes a single request/response exchange, filling resp. It is safe for concurrent use: each call takes its own connection from the pool.
func (*Transport) SetDialTimeout ¶
SetDialTimeout overrides the default 10s dial timeout.
func (*Transport) SetMaxIdleConns ¶
SetMaxIdleConns caps the number of idle conns held in the pool. Surplus conns close on return.
func (*Transport) SetReadTimeout ¶
SetReadTimeout overrides the default 30s response-read timeout.