echo

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package echo is a self-contained demo of zapgen interface (RPC) codegen.

echo.zap declares two structs (Ping, Pong) and an Echo service with four methods covering every shape: request+response, request-only (void return), response-only (no request), and bare (no params). The *_zap.go files are generated by zapgen and checked in; echo_test.go drives the generated EchoClient through DispatchEcho against a hand-written EchoHandler over an in-memory channel, proving the ordinal-routed call envelope round-trips.

Index

Constants

View Source
const (
	EchoPingOrdinal     uint32 = 1
	EchoNotifyOrdinal   uint32 = 2
	EchoHealthOrdinal   uint32 = 3
	EchoShutdownOrdinal uint32 = 4
)

Method ordinals for the Echo service (stable 1-based wire ids).

Variables

This section is empty.

Functions

func DispatchEcho

func DispatchEcho(h EchoHandler, envelope []byte) ([]byte, error)

DispatchEcho decodes a Call envelope, routes it by method ordinal to h, and returns the response envelope. An unknown ordinal yields a StatusNotFound response; a handler error yields StatusInternal.

func NewPing

func NewPing(in PingInput) []byte

NewPing builds a ZAP-encoded Ping message from in and returns the bytes.

func NewPong

func NewPong(in PongInput) []byte

NewPong builds a ZAP-encoded Pong message from in and returns the bytes.

Types

type EchoChannel

type EchoChannel interface {
	Call(envelope []byte) (rpc.Response, error)
}

EchoChannel ships one Call envelope and awaits its correlated Response.

type EchoClient

type EchoClient struct {
	// contains filtered or unexported fields
}

EchoClient is a typed RPC client for the Echo service over a ZAP call channel. Each call takes a fresh PromiseID from sess; the pipelined "On" form of a method sets Target to a prior call's Promise so the server chains them.

func NewEchoClient

func NewEchoClient(ch EchoChannel, capability []byte) *EchoClient

NewEchoClient returns a client that issues calls over ch, attaching cap (which may be nil) to every request.

func (*EchoClient) Health

func (c *EchoClient) Health() (rpc.Promise, []byte, error)

func (*EchoClient) HealthOn added in v1.4.0

func (c *EchoClient) HealthOn(on rpc.Promise) (rpc.Promise, []byte, error)

HealthOn issues Health as a dependent call pipelined on the answer of on: the server substitutes on's resolved result for this call's payload before dispatch, so it ships without waiting for on to round-trip.

func (*EchoClient) Notify

func (c *EchoClient) Notify(req []byte) (rpc.Promise, error)

func (*EchoClient) NotifyOn added in v1.4.0

func (c *EchoClient) NotifyOn(on rpc.Promise) (rpc.Promise, error)

NotifyOn issues Notify as a dependent call pipelined on the answer of on: the server substitutes on's resolved result for this call's payload before dispatch, so it ships without waiting for on to round-trip.

func (*EchoClient) Ping

func (c *EchoClient) Ping(req []byte) (rpc.Promise, []byte, error)

func (*EchoClient) PingOn added in v1.4.0

func (c *EchoClient) PingOn(on rpc.Promise) (rpc.Promise, []byte, error)

PingOn issues Ping as a dependent call pipelined on the answer of on: the server substitutes on's resolved result for this call's payload before dispatch, so it ships without waiting for on to round-trip.

func (*EchoClient) Shutdown

func (c *EchoClient) Shutdown() (rpc.Promise, error)

func (*EchoClient) ShutdownOn added in v1.4.0

func (c *EchoClient) ShutdownOn(on rpc.Promise) (rpc.Promise, error)

ShutdownOn issues Shutdown as a dependent call pipelined on the answer of on: the server substitutes on's resolved result for this call's payload before dispatch, so it ships without waiting for on to round-trip.

type EchoHandler

type EchoHandler interface {
	Ping(req []byte) ([]byte, error)
	Notify(req []byte) error
	Health() ([]byte, error)
	Shutdown() error
}

EchoHandler is the server contract for the Echo service. Implement each method, then route requests to it with DispatchEcho.

type Ping

type Ping struct {
	// contains filtered or unexported fields
}

Ping is a zero-copy view into a ZAP-encoded Ping message.

func WrapPing

func WrapPing(b []byte) (Ping, error)

WrapPing parses b and returns a typed view. Returns an error if the wire-level checks (magic, version, size) fail.

func (Ping) Seq

func (t Ping) Seq() uint64

type PingInput

type PingInput struct {
	Seq uint64
}

PingInput collects the field values for NewPing.

type Pong

type Pong struct {
	// contains filtered or unexported fields
}

Pong is a zero-copy view into a ZAP-encoded Pong message.

func WrapPong

func WrapPong(b []byte) (Pong, error)

WrapPong parses b and returns a typed view. Returns an error if the wire-level checks (magic, version, size) fail.

func (Pong) Seq

func (t Pong) Seq() uint64

type PongInput

type PongInput struct {
	Seq uint64
}

PongInput collects the field values for NewPong.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL