Documentation
¶
Overview ¶
Package rpc implements unary calls in the Connect protocol on net/http: https://connectrpc.com/docs/protocol
Messages travel as uncompressed binary Protobuf; a handler also accepts JSON. The package supports neither streaming, nor the gRPC and gRPC-Web protocols.
Index ¶
- Constants
- func CallUnary[Res, Req any, PRes message[Res], PReq message[Req]](ctx context.Context, c *Client, procedure string, req *Req) (*Res, error)
- func NewServiceHandler(service string, handlers ...*Handler) (string, http.Handler)
- type Client
- type ClientOption
- type Code
- type Error
- type HTTPClient
- type Handler
- type HandlerOption
- type Interceptor
- type Option
- type UnaryFunc
Constants ¶
const ( CodeCanceled = clientrpc.CodeCanceled CodeUnknown = clientrpc.CodeUnknown CodeInvalidArgument = clientrpc.CodeInvalidArgument CodeDeadlineExceeded = clientrpc.CodeDeadlineExceeded CodeNotFound = clientrpc.CodeNotFound CodeAlreadyExists = clientrpc.CodeAlreadyExists CodePermissionDenied = clientrpc.CodePermissionDenied CodeResourceExhausted = clientrpc.CodeResourceExhausted CodeFailedPrecondition = clientrpc.CodeFailedPrecondition CodeAborted = clientrpc.CodeAborted CodeOutOfRange = clientrpc.CodeOutOfRange CodeUnimplemented = clientrpc.CodeUnimplemented CodeInternal = clientrpc.CodeInternal CodeDataLoss = clientrpc.CodeDataLoss CodeUnauthenticated = clientrpc.CodeUnauthenticated )
Variables ¶
This section is empty.
Functions ¶
func CallUnary ¶
func CallUnary[Res, Req any, PRes message[Res], PReq message[Req]](ctx context.Context, c *Client, procedure string, req *Req) (*Res, error)
CallUnary sends req to procedure, for example "/resolver.v1.ResolverService/GetSecrets", and returns the response. A deadline on ctx travels to the server. A call that fails returns an *Error; an interceptor may return any error.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the procedures of one server.
func NewClient ¶
func NewClient(httpClient HTTPClient, baseURL string, opts ...ClientOption) *Client
NewClient returns a client for the server at baseURL, for example "http://unix".
type ClientOption ¶
type ClientOption interface {
// contains filtered or unexported methods
}
ClientOption configures a Client.
type HTTPClient ¶
type HTTPClient = clientrpc.HTTPClient
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves one procedure.
func NewUnaryHandler ¶
func NewUnaryHandler[Req, Res any, PReq message[Req], PRes message[Res]]( procedure string, unary func(context.Context, *Req) (*Res, error), opts ...HandlerOption, ) *Handler
NewUnaryHandler returns the handler of procedure, for example "/resolver.v1.ResolverService/GetSecrets". The caller sees an error that unary returns with its code if it is an *Error, with CodeCanceled or CodeDeadlineExceeded if it is a context error, and with CodeUnknown otherwise.
type HandlerOption ¶
type HandlerOption interface {
// contains filtered or unexported methods
}
HandlerOption configures a Handler.
type Interceptor ¶
Interceptor wraps a call, on the client or in the handler, for example to reject the call or to measure it.
type Option ¶
type Option interface {
ClientOption
HandlerOption
}
Option configures a Client or a Handler.
func WithInterceptors ¶
func WithInterceptors(interceptors ...Interceptor) Option
WithInterceptors wraps the calls of a client, or a handler, in interceptors. The first interceptor is the outermost: it sees the request first and the response last.