Documentation
¶
Index ¶
- Constants
- func AppendRequest(dst []byte, req *fasthttp.Request) ([]byte, error)
- func AppendResponse(dst []byte, resp *fasthttp.Response) ([]byte, error)
- func DataChunkOf(frame []byte) ([]byte, error)
- func FrameTypeOf(frame []byte) (uint16, error)
- func Get(addr, path string) (*fasthttp.Response, error)
- func ListenAndServe(addr string, handler fasthttp.RequestHandler) error
- func MarshalData(chunk []byte) []byte
- func MarshalEnd(trailer []byte) []byte
- func MarshalRequest(req *fasthttp.Request) ([]byte, error)
- func MarshalResponse(resp *fasthttp.Response) ([]byte, error)
- func MarshalResponseHead(resp *fasthttp.Response) ([]byte, error)
- func UnmarshalRequest(frame []byte, dst *fasthttp.Request) error
- func UnmarshalResponse(frame []byte, dst *fasthttp.Response) error
- func UnmarshalResponseHead(frame []byte, dst *fasthttp.Response) error
- type Server
- type Transport
Constants ¶
const ( FrameRequest uint16 = 0x01 FrameResponse uint16 = 0x02 // Streaming response frames. A streamed response is a FrameResponseHead // (status + headers, no body) followed by zero or more FrameData chunks and // a terminating FrameEnd (optional trailers). This is how server→client // push (SSE, MCP notifications, chunked bodies) rides ZAP — the analogue of // HTTP/2 HEADERS + DATA + END_STREAM. The non-streaming FrameResponse path // is unchanged, so existing peers interoperate. FrameResponseHead uint16 = 0x03 FrameData uint16 = 0x04 FrameEnd uint16 = 0x05 )
Frame type IDs. The ZAP message header carries the type in the upper byte of the 16-bit flags field; the encoder tags the message with type<<8 and flags>>8 recovers it. A request frame and a response frame are the two shapes the non-streaming wire carries.
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 AppendRequest ¶ added in v0.2.1
AppendRequest appends a request frame to dst and returns the extended slice. Passing a reused (len-0) buffer makes the steady-state marshal zero-alloc; MarshalRequest is the dst==nil convenience.
func AppendResponse ¶ added in v0.2.1
AppendResponse appends a response frame to dst and returns the extended slice. See AppendRequest.
func DataChunkOf ¶ added in v0.2.0
DataChunkOf extracts the chunk bytes from a FrameData frame. The returned slice aliases the frame buffer; copy it to retain past the frame's lifetime.
func FrameTypeOf ¶ added in v0.2.0
FrameTypeOf peeks a frame's type from its ZAP header without decoding the body, so a reader can dispatch (response vs streamed head vs data vs end).
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 MarshalData ¶ added in v0.2.0
MarshalData wraps one body chunk as a FrameData frame.
func MarshalEnd ¶ added in v0.2.0
MarshalEnd terminates a stream, carrying optional encoded trailers.
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). It is the dst==nil convenience for AppendRequest — hot callers append into a reused buffer to stay allocation-free.
func MarshalResponse ¶
MarshalResponse serializes a *fasthttp.Response into a ZAP frame. See MarshalRequest; AppendResponse is the reused-buffer form.
func MarshalResponseHead ¶ added in v0.2.0
MarshalResponseHead serializes a response's status + headers (NO body) as the opening frame of a stream. The body is delivered by subsequent FrameData frames.
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 comes from a Host header if the frame carried one.
func UnmarshalResponse ¶
UnmarshalResponse reconstructs a response into dst from a ZAP frame.
Types ¶
type Server ¶
type Server struct {
Addr string // ":9999" if empty
// Network mirrors net.Listen's first argument: "tcp" when empty, or
// "unix" to serve the same ZAP frames on a socket path given in Addr.
// The wire is identical either way; only the plumbing differs.
Network string
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 over a pooled connection. Field-zero is invalid; use Dial.
func Dial ¶ added in v0.2.2
Dial returns a Transport that speaks ZAP to addr over network, mirroring net.Dial: the network is a value ("tcp", "unix", …), not a family of functions. A unix address is a socket path and carries the same ZAP frames as tcp — the wire does not change with the network.
http.Dial("tcp", "billing.hanzo.svc:9653")
http.Dial("unix", "/run/hanzo/billing.sock")
Dialing is lazy; the first request opens the connection.
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.