Documentation
¶
Overview ¶
Package connect is a slim RPC framework built on Protocol Buffers and net/http. In addition to supporting its own protocol, Connect handlers and clients are wire-compatible with gRPC and gRPC-Web, including streaming.
This documentation is intended to explain each type and function in isolation. Walkthroughs, FAQs, and other narrative docs are available on the Connect website, and there's a working demonstration service on Github.
Index ¶
- Constants
- func DecodeBinaryHeader(data string) ([]byte, error)
- func EncodeBinaryHeader(data []byte) string
- type CallInfo
- type Client
- type ClientFunc
- type ClientInterceptor
- type ClientStream
- type Code
- type Codec
- type Compressor
- type Error
- func (e *Error) Code() Code
- func (e *Error) Details() []*ErrorDetail
- func (e *Error) Error() string
- func (e *Error) IsRemote() bool
- func (e *Error) Message() string
- func (e *Error) Unwrap() error
- func (e *Error) WithCause(err error) *Error
- func (e *Error) WithDetail(detail *ErrorDetail) *Error
- func (e *Error) WithRemote() *Error
- type ErrorDetail
- type Header
- func (m *Header) Add(key, value string)
- func (m *Header) All() iter.Seq2[string, []string]
- func (m *Header) Delete(key string)
- func (m *Header) Get(key string) string
- func (m *Header) Has(key string) bool
- func (m *Header) Len() int
- func (m *Header) Set(key, value string)
- func (m *Header) SetValues(key string, values []string)
- func (m *Header) Values(key string) []string
- type IdempotencyLevel
- type MessageStats
- type Method
- type Server
- type ServerFunc
- type ServerInterceptor
- type ServerStream
- type Spec
- type StableCodec
- type StreamType
- type Transport
Constants ¶
const ( // CodecNameProto is the protocol token for protobuf binary encoding. CodecNameProto = "proto" // CodecNameJSON is the protocol token for protobuf JSON encoding. CodecNameJSON = "json" )
Well-known codec names.
const ( // CompressionNameIdentity is the token for uncompressed messages. It is // named so transport metadata can report "identity" consistently even // though no compressor is needed. CompressionNameIdentity = "identity" // CompressionNameGzip is the token for gzip compression. CompressionNameGzip = "gzip" // CompressionNameBr is the token for Brotli compression. The core package // defines the name so transports and compressor packages can agree on the // token. It does not provide a Brotli compressor. CompressionNameBr = "br" // CompressionNameZstd is the token for Zstandard compression. The core // package defines the name so transports and compressor packages can agree // on the token. It does not provide a Zstandard compressor. CompressionNameZstd = "zstd" )
Well-known compression names.
const ( // ProtocolNameConnect is the token for the Connect protocol. ProtocolNameConnect = "connect" // ProtocolNameGRPC is the token for the gRPC protocol. ProtocolNameGRPC = "grpc" // ProtocolNameGRPCWeb is the token for the gRPC-Web protocol. ProtocolNameGRPCWeb = "grpcweb" )
Well-known protocol names reported by CallInfo.Protocol.
const Version = "2.0.0-dev"
Version is the semantic version of the connect module.
Variables ¶
This section is empty.
Functions ¶
func DecodeBinaryHeader ¶
DecodeBinaryHeader base64-decodes the data. It can decode padded or unpadded values. Following usual HTTP semantics, multiple base64-encoded values may be joined with a comma. When receiving such comma-separated values, split them with strings.Split before calling DecodeBinaryHeader.
Binary headers sent using the Connect, gRPC, and gRPC-Web protocols have keys ending in "-Bin".
func EncodeBinaryHeader ¶
EncodeBinaryHeader base64-encodes the data. It always emits unpadded values.
In the Connect, gRPC, and gRPC-Web protocols, binary headers must have keys ending in "-Bin".
Types ¶
type CallInfo ¶
type CallInfo struct {
// Spec describes the RPC procedure.
Spec Spec
// PeerAddr is the remote peer's address, or empty when the transport has
// no network peer.
PeerAddr string
// Protocol is the wire protocol, such as "connect", "grpc", or "grpcweb".
Protocol string
// Codec is the codec name, such as "proto" or "json".
Codec string
// RequestEncoding is the request compression, "identity" when
// uncompressed.
RequestEncoding string
// ResponseEncoding is the response compression, "identity" when
// uncompressed.
ResponseEncoding string
// SendStats holds byte counts for the most recent Send.
SendStats MessageStats
// ReceiveStats holds byte counts for the most recent Receive.
ReceiveStats MessageStats
// TransportInfo is optional transport-specific metadata, such as
// [connectrpc.com/connect/v2/connecthttp.ClientInfo] or
// [connectrpc.com/connect/v2/connecthttp.ServerInfo].
TransportInfo any
// contains filtered or unexported fields
}
CallInfo describes an RPC as it runs. Clients reach it with NewClientContext, servers with CallInfoForServerContext. The two sides use separate context keys, so a handler's outbound calls don't share its inbound metadata.
The transport populates the fields: request-side fields before dispatch, response-side fields and stats as messages flow. On a streaming RPC, reading a field before the matching Send or Receive returns races the transport.
func CallInfoForClientContext ¶
CallInfoForClientContext returns the client-side CallInfo attached to ctx, if there is one. Client call methods attach a fresh CallInfo before invoking the interceptor chain when ctx does not already carry one, so client interceptors and the Transport can rely on it being present. Outside a Client call, it reports false unless the caller used NewClientContext.
func CallInfoForServerContext ¶
CallInfoForServerContext returns the server-side CallInfo attached by Server.Call before invoking interceptors and generated handlers, if there is one. It reports false if the call did not come through Server.Call (e.g., a raw ServerFunc invocation in a test).
func NewClientContext ¶
NewClientContext attaches a fresh client-side CallInfo to ctx and returns both. Use it to set request metadata before issuing an RPC, or to read response metadata after the call. A reused handle reports the most recent call. For concurrent calls, derive a separate context per call.
func (*CallInfo) RequestHeader ¶
RequestHeader returns the request headers. The client sets them before the first Send, and the server reads them.
func (*CallInfo) ResponseHeader ¶
ResponseHeader returns the response headers. The server sets them before its first Send, and the client reads them once the response arrives.
func (*CallInfo) ResponseTrailer ¶
ResponseTrailer returns the response trailers. The server sets them before the stream ends, and the client reads them after receiving to io.EOF.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client bundles a Transport with the client-side interceptor chain. Generated service clients hold a *Client and dispatch every RPC through one of the Call methods.
The interceptor chain is applied once in NewClient, producing one prebuilt ClientFunc.
func NewClient ¶
func NewClient(transport Transport, interceptors ...ClientInterceptor) *Client
NewClient returns a Client that dispatches RPCs over transport. The interceptors fire in argument order. The first wraps the outermost call. Interceptors that need per-message behavior wrap the ClientStream that next returns.
The interceptor chain is applied here, once, not on every RPC. Per-RPC state belongs in the ClientFunc an interceptor returns, or in a ClientStream wrapper, not in the interceptor function itself.
func (*Client) CallClientStream ¶
CallClientStream opens a stream for spec for client-streaming or bidi RPCs. The returned ClientStream is wrapped by interceptors when any are configured.
The stream's underlying resources are released automatically when ClientStream.Receive returns io.EOF or the RPC context is canceled. To abandon a stream before reading to completion, cancel the context or call ClientStream.Close.
func (*Client) CallServerStream ¶
CallServerStream opens a stream for spec, sends the single request, closes the send side, and returns the stream for the caller to read responses from. The returned ClientStream is wrapped by interceptors when any are configured.
Its resources are released automatically when ClientStream.Receive returns io.EOF or the RPC context is canceled. To abandon the stream early, cancel the context or call ClientStream.Close.
func (*Client) CallUnary ¶
CallUnary opens a stream for spec, sends req, closes the send side, and reads a single response into res.
The initialization passes through the interceptor chain. The full ClientStream.Send, ClientStream.CloseSend, and ClientStream.Receive sequence is then executed on the resulting stream. Receive reads the response to io.EOF, which releases the stream's resources.
type ClientFunc ¶
type ClientFunc func(ctx context.Context, spec Spec) (ClientStream, error)
ClientFunc opens a ClientStream for an RPC. Interceptors wrap one ClientFunc to produce another. The innermost function invokes the Transport to establish the connection and initialize the stream.
type ClientInterceptor ¶
type ClientInterceptor func(next ClientFunc) ClientFunc
ClientInterceptor wraps a ClientFunc. It may return an error without calling next to short-circuit the RPC.
Unlike server interceptors, client interceptors wrap the initialization of the stream rather than the full execution of the RPC. This model is identical across unary and streaming calls. Because next opens the stream, deriving a new context and passing it to next propagates that context to the Transport and the stream. To observe or modify messages, interceptors call next and wrap the returned ClientStream. To observe the end of the RPC, wrap both Close and Receive: streaming callers may finish at io.EOF without calling Close.
NewClient applies the chain when the client is constructed, so the interceptor function runs once, not once per RPC. Keep per-RPC state in the returned ClientFunc or stream wrapper.
type ClientStream ¶
type ClientStream interface {
// SendHeaders flushes the request headers and opens the stream without
// sending a request message. The first Send or Receive does this
// implicitly; call SendHeaders only to flush eagerly, for example to let
// the server begin work, surface connection errors before the first
// message, or record timing. It is idempotent.
SendHeaders() error
// Send sends msg as the next request message.
Send(msg any) error
// CloseSend closes the request side of the stream. It is idempotent.
CloseSend() error
// Receive reads the next response message into msg. It reports clean
// receive-side completion with an error that matches io.EOF under errors.Is.
// Reading to io.EOF releases the stream's resources; to abandon a stream
// earlier, cancel the call's context or call Close.
Receive(msg any) error
// Close releases the stream's resources, unblocking a pending Receive and
// tearing the stream down. It may be called concurrently with Receive,
// typically as defer stream.Close(). It is idempotent. After Close, the
// stream must not be used again.
Close() error
}
ClientStream is the client-side view of a single in-flight RPC.
A caller drives the stream by sending request messages, closing the send side with CloseSend, and receiving response messages until Receive reports the end of the response stream with an error matching io.EOF under errors.Is. Reading to io.EOF releases the stream's resources and makes the response trailers available on the call's CallInfo. To abandon a stream before io.EOF, cancel the context passed to the Client call: that releases resources and unblocks any pending operation. Client.CallUnary drives this full sequence internally.
The first Send or Receive flushes the request headers from CallInfo.RequestHeader and opens the stream. Call ClientStream.SendHeaders to flush them eagerly without sending a message. After the headers are flushed, later mutations to the request headers may not affect the request.
Send transmits request messages, and Receive reads response messages. The msg passed to Send and Receive must match the message type described by the stream's Spec. Generated wrappers expose typed methods for the legal operations, but raw stream users must follow Spec.StreamType themselves.
A stream supports one active send-side operation and one active receive-side operation at a time, and the two sides may run concurrently. Do not call Send concurrently with Send or CloseSend, and do not call Receive concurrently with Receive.
RPC status and protocol errors returned by streams can be inspected with errors.As into *Error or classified with CodeOf. Clean receive-side completion is reported by an error that matches io.EOF under errors.Is. Context cancellation may be reported directly as context.Canceled or context.DeadlineExceeded, or as an *Error whose cause matches one of those errors.
The stream does not expose Spec or CallInfo. The Spec is passed alongside the stream into ClientFunc, and the CallInfo is reached through ctx via CallInfoForClientContext.
type Code ¶
type Code uint32
Code is a Connect error code.
const ( // CodeCanceled indicates that the operation was canceled, typically by the // caller. CodeCanceled Code = 1 // CodeUnknown indicates that the operation failed for an unknown reason. CodeUnknown Code = 2 // CodeInvalidArgument indicates that client supplied an invalid argument. CodeInvalidArgument Code = 3 // CodeDeadlineExceeded indicates that deadline expired before the operation // could complete. CodeDeadlineExceeded Code = 4 // CodeNotFound indicates that some requested entity (for example, a file or // directory) was not found. CodeNotFound Code = 5 // CodeAlreadyExists indicates that client attempted to create an entity (for // example, a file or directory) that already exists. CodeAlreadyExists Code = 6 // CodePermissionDenied indicates that the caller doesn't have permission to // execute the specified operation. CodePermissionDenied Code = 7 // CodeResourceExhausted indicates that some resource has been exhausted. For // example, a per-user quota may be exhausted or the entire file system may // be full. CodeResourceExhausted Code = 8 // CodeFailedPrecondition indicates that the system is not in a state // required for the operation's execution. CodeFailedPrecondition Code = 9 // CodeAborted indicates that operation was aborted by the system, usually // because of a concurrency issue such as a sequencer check failure or // transaction abort. CodeAborted Code = 10 // CodeOutOfRange indicates that the operation was attempted past the valid // range (for example, seeking past end-of-file). CodeOutOfRange Code = 11 // CodeUnimplemented indicates that the operation isn't implemented, // supported, or enabled in this service. CodeUnimplemented Code = 12 // CodeInternal indicates that some invariants expected by the underlying // system have been broken. This code is reserved for serious errors. CodeInternal Code = 13 // is usually temporary, so clients can back off and retry idempotent // operations. CodeUnavailable Code = 14 // CodeDataLoss indicates that the operation has resulted in unrecoverable // data loss or corruption. CodeDataLoss Code = 15 // CodeUnauthenticated indicates that the request does not have valid // authentication credentials for the operation. CodeUnauthenticated Code = 16 )
Standard Connect RPC codes. Code.String returns the lowercase protocol token for each code.
func CodeOf ¶
CodeOf returns the Connect code carried by err. If err does not wrap an *Error, CodeOf returns CodeUnknown. Passing nil is not meaningful and also returns CodeUnknown.
func (Code) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Code) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Codec ¶
type Codec interface {
// Name returns the protocol codec token, such as "proto" or "json".
Name() string
// MarshalWrite encodes msg to dst. The encoding must be complete when
// MarshalWrite returns. Any write error from dst must be returned
// directly or wrapped with %w.
MarshalWrite(ctx context.Context, dst io.Writer, msg any) error
// UnmarshalRead decodes one message from src into msg. src is bounded to
// that message and reports [io.EOF] once the payload is consumed. Any read
// error from src must be returned directly or wrapped with %w. The transport
// drains any unread bytes once it returns.
UnmarshalRead(ctx context.Context, src io.Reader, msg any) error
}
Codec marshals and unmarshals RPC messages. Implementations must be safe for concurrent use. Method contexts carry per-call values. Codecs are not required to observe cancellation.
Transports pass io.Writer and io.Reader so codecs may stream when their encoding supports it. Codecs that need contiguous input or output should buffer internally. Writers from this module also expose the AvailableBuffer and Grow methods of bytes.Buffer for append-style encoders.
dst and src are valid only for the duration of the call. A codec must not retain or use either after it returns.
type Compressor ¶
type Compressor interface {
// Name returns the content-encoding token, such as "gzip".
Name() string
// Compress returns a writer that writes compressed bytes to dst. Closing
// the writer flushes buffered data and releases resources. Callers must
// close the writer exactly once and must not use it after Close.
Compress(dst io.Writer) (io.WriteCloser, error)
// Decompress returns a reader for the decompressed form of src. Closing
// the reader releases resources without closing src. Callers must close
// the reader exactly once, even if it was not fully consumed, and must not
// use it after Close.
Decompress(src io.Reader) (io.ReadCloser, error)
}
Compressor compresses and decompresses RPC payloads. Implementations must be safe for concurrent use.
The writers and readers returned by Compressor methods own per-payload state. They are used by one goroutine at a time and must be closed exactly once. Implementations may pool state and recycle it on Close.
The returned writer may retain dst until Close, and the returned reader may retain src until Close. They must not write to dst or read from src after Close. Transports enforce decompressed-size limits by wrapping the reader returned from Decompress.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is the Connect error type. Code, message, and supported detail values may be serialized by transports. Cause and remote are local process metadata and are never serialized.
Handlers fail an RPC by returning an error, but only a locally authored *Error carries its code, message, and details to the wire. Transports must not serialize other errors: clients see only a code, typically CodeUnknown, with no message. Text sent to callers is therefore always constructed intentionally with NewError or Errorf.
func Errorf ¶
Errorf returns a new *Error with the given code and a formatted public message. The message is serialized to the wire. Do not include sensitive details.
Errorf uses fmt.Sprintf and does not attach wrapped errors. Use Error.WithCause for local-only causes.
func NewError ¶
NewError returns a new *Error with code and a public message. The message is serialized to the wire. Do not include sensitive details.
func (*Error) Code ¶
Code returns the Connect error code. If the stored code is zero, Code returns CodeUnknown.
func (*Error) Details ¶
func (e *Error) Details() []*ErrorDetail
Details returns a copy of the error's detail list. Decode each detail with a codec package, such as connectrpc.com/connect/v2/connectproto.UnmarshalErrorDetail.
func (*Error) IsRemote ¶
IsRemote reports whether this error is a peer's RPC verdict rather than the local handler's own. Server transports must not forward a remote Error as the handler's own RPC verdict.
func (*Error) Message ¶
Message returns the optional human-readable error message serialized on the wire.
func (*Error) Unwrap ¶
Unwrap returns the local cause for errors.Is and errors.As. The cause is not serialized.
func (*Error) WithCause ¶
WithCause returns a cloned error with err attached as a local cause. Causes are available to errors.Is and errors.As but are not serialized. A nil cause is ignored.
func (*Error) WithDetail ¶
func (e *Error) WithDetail(detail *ErrorDetail) *Error
WithDetail returns a cloned error with detail appended as a public detail value. Construct details with a codec package, such as connectrpc.com/connect/v2/connectproto.NewErrorDetail. A nil detail is ignored.
func (*Error) WithRemote ¶
WithRemote returns a cloned error marked as a peer's RPC verdict.
type ErrorDetail ¶
type ErrorDetail struct {
// Type is the fully-qualified message type name, such as
// "google.rpc.RetryInfo".
Type string
// Value is the serialized message.
Value []byte
// Debug is an optional human-readable representation of Value, carried
// by the Connect protocol as the detail's "debug" JSON. It is best
// effort: transports may regenerate or omit it.
Debug []byte
}
ErrorDetail is a self-describing message attached to an *Error. On the Connect, gRPC, and gRPC-Web protocols, details are Protobuf messages: construct them with connectrpc.com/connect/v2/connectproto.NewErrorDetail and decode them with connectrpc.com/connect/v2/connectproto.UnmarshalErrorDetail.
type Header ¶
type Header struct {
// contains filtered or unexported fields
}
Header is a mutable, case-insensitive, multi-valued string map, mirroring net/http.Header. The zero value is ready to use. Header is not safe for concurrent use.
Keys are canonicalized with textproto.CanonicalMIMEHeaderKey. Transports ignore or overwrite protocol-reserved keys when sending an RPC.
func (*Header) All ¶
All yields each key and its values in unspecified order. The yielded slices alias the header.
func (*Header) Get ¶
Get returns the first value associated with key, or "" if the key has no values.
type IdempotencyLevel ¶
type IdempotencyLevel int32
IdempotencyLevel mirrors the protobuf MethodOptions idempotency_level.
const ( // IdempotencyUnknown means the schema does not declare an idempotency // level. IdempotencyUnknown IdempotencyLevel = 0 // IdempotencyNoSideEffects means the RPC has no side effects. Transports // may use this to enable protocol features such as Connect GET. IdempotencyNoSideEffects IdempotencyLevel = 1 // IdempotencyIdempotent means repeated identical requests have the same // effect as one request. IdempotencyIdempotent IdempotencyLevel = 2 )
IdempotencyLevel values mirror protobuf MethodOptions.idempotency_level.
func (IdempotencyLevel) String ¶
func (i IdempotencyLevel) String() string
String returns a human-readable idempotency-level name.
type MessageStats ¶
type MessageStats struct {
// Size is the uncompressed payload size in bytes.
Size int
// CompressedSize is the compressed payload size in bytes. It is zero when
// the message is uncompressed.
CompressedSize int
}
MessageStats holds byte counts for one RPC message. The counts exclude envelope framing, HTTP headers, and trailers.
type Method ¶
type Method struct {
// Spec describes the RPC procedure being registered.
Spec Spec
// Handler serves the RPC described by Spec.
Handler ServerFunc
}
Method binds a Spec to the ServerFunc that serves it.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the procedure-to-method dispatcher. It owns the method registry and the server-side interceptor chain.
func NewServer ¶
func NewServer(interceptors ...ServerInterceptor) *Server
NewServer returns a dispatcher with no registered methods. The interceptors fire in argument order. The first wraps the outermost call. Interceptors that need per-message behavior should wrap the ServerStream before calling next.
func (*Server) Call ¶
func (s *Server) Call(ctx context.Context, procedure string, info *CallInfo, stream ServerStream) error
Call dispatches an RPC to the method registered for procedure. Transports build the ServerStream from their wire input, pass the per-RPC CallInfo (or nil to let Call allocate one), and Call attaches it to ctx so user handlers can read it via CallInfoForServerContext. Call returns the method error for the transport to encode in its protocol. It does not finalize protocol state. The transport does that once Call returns. Returns CodeUnimplemented when no method is registered.
func (*Server) Register ¶
Register stores each method on the dispatcher. Each Method.Handler is wrapped with the server-side interceptor chain so Server.Call is just a map lookup plus one call.
Register panics if two methods have the same Spec.Procedure. Register is intended for setup and must not run concurrently with Server.Register, Server.Specs, or Server.Call.
func (*Server) SetUnknownHandler ¶
func (s *Server) SetUnknownHandler(fn ServerFunc)
SetUnknownHandler sets the fallback ServerFunc that Server.Call invokes when no method is registered for a procedure. The handler receives a Spec whose Procedure is the requested procedure and whose StreamType is StreamTypeBidi, the most permissive shape, since the cardinality of an unregistered procedure is unknown. Its Schema is nil. The handler is wrapped by the server interceptor chain like a registered method. A nil fn restores the default, which fails the call with CodeUnimplemented.
SetUnknownHandler is intended for setup and must not run concurrently with Server.Call or Server.Register.
type ServerFunc ¶
type ServerFunc func(ctx context.Context, spec Spec, stream ServerStream) error
ServerFunc serves an RPC on an open ServerStream. Interceptors wrap one ServerFunc to produce another. The innermost function is the registered Method.Handler.
type ServerInterceptor ¶
type ServerInterceptor func(next ServerFunc) ServerFunc
ServerInterceptor wraps a ServerFunc. It may return an error without calling next to short-circuit the RPC.
Server interceptors surround the full server invocation. To observe or modify individual messages, interceptors can pass a wrapped ServerStream to next.
type ServerStream ¶
type ServerStream interface {
// Receive reads the next request message into msg. It reports clean
// receive-side completion with an error that matches io.EOF under errors.Is.
Receive(msg any) error
// SendHeaders flushes the response headers and opens the stream without
// sending a response message. The first Send does this implicitly; call
// SendHeaders only to flush eagerly, for example to let the client begin
// work or surface headers before the first Send. It is idempotent.
SendHeaders() error
// Send sends msg as the next response message.
Send(msg any) error
}
ServerStream is the server-side view of a single in-flight RPC. The Spec is passed alongside the stream into ServerFunc, and the CallInfo is reached through ctx via CallInfoForServerContext.
The first Send flushes the response headers from CallInfo.ResponseHeader. Call ServerStream.SendHeaders to flush them eagerly without sending a response message. After the headers are flushed, later mutations to the response headers may not affect the response.
Receive reads request messages, and Send transmits response messages. The msg passed to Receive and Send must match the message type described by the stream's Spec. Generated wrappers expose typed methods for the legal operations, but raw stream users must follow Spec.StreamType themselves.
A stream supports one active send-side operation and one active receive-side operation at a time, and the two sides may run concurrently. Do not call Send concurrently with Send, and do not call Receive concurrently with Receive.
The server stream has no Close method: the transport finalizes the RPC when the handler returns, encoding the handler's error and any trailers. Handler code ends the RPC by returning, not by closing the stream.
RPC status and protocol errors returned by streams can be inspected with errors.As into *Error or classified with CodeOf. Clean receive-side completion is reported by an error that matches io.EOF under errors.Is. Context cancellation may be reported directly as context.Canceled or context.DeadlineExceeded, or as an *Error whose cause matches one of those errors.
type Spec ¶
type Spec struct {
// StreamType describes which side, if any, sends multiple messages.
// It controls which stream operations generated wrappers expose.
StreamType StreamType
// IdempotencyLevel mirrors protobuf MethodOptions.idempotency_level.
// Transports may use it for protocol features such as Connect GET.
IdempotencyLevel IdempotencyLevel
// Schema is opaque method schema information. Protobuf generated code
// stores a protoreflect.MethodDescriptor. Other schema systems may use
// their own descriptor types.
Schema any
// Procedure is the leading-slash RPC path, such as
// "/package.Service/Method". Server uses it as the registry key, and
// HTTP transports use it as the route path.
Procedure string
}
Spec describes a single RPC procedure. Generated code typically provides one Spec per protobuf method.
type StableCodec ¶
type StableCodec interface {
Codec
// MarshalWriteStable encodes msg deterministically to dst. Messages
// equivalent under the codec's schema rules must produce identical bytes.
// The dst writer follows the rules of [Codec.MarshalWrite].
MarshalWriteStable(ctx context.Context, dst io.Writer, msg any) error
// IsBinary reports whether MarshalWriteStable writes binary data. Binary
// encodings are text-encoded before use in URLs.
IsBinary() bool
}
StableCodec is a Codec with a deterministic encoding. Transports use stable encodings for features such as Connect GET request URLs.
type StreamType ¶
type StreamType uint8
StreamType describes the directionality of an RPC.
const ( // StreamTypeUnary identifies an RPC with one request and one response. StreamTypeUnary StreamType = 0b00 // StreamTypeClient identifies a client-streaming RPC. StreamTypeClient StreamType = 0b01 // StreamTypeServer identifies a server-streaming RPC. StreamTypeServer StreamType = 0b10 // StreamTypeBidi identifies a bidirectional-streaming RPC. StreamTypeBidi = StreamTypeClient | StreamTypeServer )
StreamType values describe the directionality of an RPC.
func (StreamType) String ¶
func (s StreamType) String() string
String returns a human-readable stream type name.
type Transport ¶
type Transport interface {
// NewClientStream opens a client stream for spec.
NewClientStream(ctx context.Context, spec Spec) (ClientStream, error)
}
Transport is the boundary between Client and an RPC execution environment. A Client passes the RPC Spec to a Transport, then drives the returned ClientStream by sending request messages, closing the send side, receiving response messages, and closing the stream. Generated clients hold a *Client rather than a Transport directly.
connectrpc.com/connect/v2/connecthttp.NewTransport returns a Transport that sends RPCs over Connect, gRPC, or gRPC-Web on net/http. Other implementations can dispatch directly to a Server, use a test double, or adapt another wire protocol without regenerating clients.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
connect-go-v2-migrate
command
Command connect-go-v2-migrate rewrites Go source code to migrate from connectrpc.com/connect to connectrpc.com/connect/v2.
|
Command connect-go-v2-migrate rewrites Go source code to migrate from connectrpc.com/connect to connectrpc.com/connect/v2. |
|
protoc-gen-connect-go
command
protoc-gen-connect-go is a plugin for the Protobuf compiler that generates Go code.
|
protoc-gen-connect-go is a plugin for the Protobuf compiler that generates Go code. |
|
Package connectgzip provides a gzip connect.Compressor for the "gzip" Content-Encoding.
|
Package connectgzip provides a gzip connect.Compressor for the "gzip" Content-Encoding. |
|
Package connecthttp adapts connect onto net/http.
|
Package connecthttp adapts connect onto net/http. |
|
Package connectinprocess provides an in-process connect.Transport.
|
Package connectinprocess provides an in-process connect.Transport. |
|
Package connectproto provides protobuf codecs for connect.
|
Package connectproto provides protobuf codecs for connect. |
|
internal
|
|
|
assert
Package assert is a minimal assert package using generics.
|
Package assert is a minimal assert package using generics. |
|
bufferpool
Package bufferpool provides a pool of reusable byte buffers shared by the codecs and transport.
|
Package bufferpool provides a pool of reusable byte buffers shared by the codecs and transport. |
|
gen/connect/ping/v1/pingv1connect
The connect.ping.v1 package contains an echo service designed to test the connect-go implementation.
|
The connect.ping.v1 package contains an echo service designed to test the connect-go implementation. |