rpc

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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
	CodeUnavailable        = clientrpc.CodeUnavailable
	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.

func NewServiceHandler

func NewServiceHandler(service string, handlers ...*Handler) (string, http.Handler)

NewServiceHandler routes the procedures of service, for example "resolver.v1.ResolverService", to handlers. It returns the path on which to mount the handler, and the handler.

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 Code

type Code = clientrpc.Code

func CodeOf

func CodeOf(err error) Code

type Error

type Error = clientrpc.Error

func NewError

func NewError(code Code, err error) *Error

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.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HandlerOption

type HandlerOption interface {
	// contains filtered or unexported methods
}

HandlerOption configures a Handler.

type Interceptor

type Interceptor func(next UnaryFunc) UnaryFunc

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.

type UnaryFunc

type UnaryFunc func(ctx context.Context, req proto.Message) (proto.Message, error)

UnaryFunc makes or handles one call.

Jump to

Keyboard shortcuts

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