rpc

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const ShutdownGracePeriod = time.Second * 5

Variables

This section is empty.

Functions

func ClientFromContext

func ClientFromContext[Client Pingable](ctx context.Context) Client

ClientFromContext returns the given RPC client from the context, or panics.

func ContextValuesMiddleware

func ContextValuesMiddleware(ctx context.Context, handler http.Handler) http.HandlerFunc

ContextValuesMiddleware injects values from a Context into the request Context.

func ContextWithClient

func ContextWithClient[Client Pingable](ctx context.Context, client Client) context.Context

ContextWithClient returns a context with an RPC client attached.

func DefaultClientOptions

func DefaultClientOptions(level log.Level) []connect.ClientOption

func DefaultHandlerOptions

func DefaultHandlerOptions() []connect.HandlerOption

func Dial

func Dial[Client Pingable](factory ClientFactory[Client], baseURL string, errorLevel log.Level, opts ...connect.ClientOption) Client

func GetHTTPClient added in v0.23.0

func GetHTTPClient(url string) *http.Client

GetHTTPClient returns a HTTP client usable for the given URL.

func InitialiseClients added in v0.23.0

func InitialiseClients(authenticators map[string]string)

InitialiseClients HTTP clients used by the RPC system.

"authenticators" are authenticator executables to use for each endpoint. The key is the URL of the endpoint, the value is the path to the authenticator executable.

func IsDirectRouted

func IsDirectRouted(ctx context.Context) bool

IsDirectRouted returns true if the incoming request should be directly routed and never redirected.

func MetadataInterceptor

func MetadataInterceptor(level log.Level) connect.Interceptor

MetadataInterceptor propagates FTL metadata through servers and clients.

func RequestNameFromContext added in v0.12.0

func RequestNameFromContext(ctx context.Context) (model.RequestName, bool, error)

RequestNameFromContext returns the request Key from the context, if any.

func RetryStreamingClientStream

func RetryStreamingClientStream[Req, Resp any](
	ctx context.Context,
	retry backoff.Backoff,
	rpc func(context.Context) *connect.ClientStreamForClient[Req, Resp],
	handler func(ctx context.Context, send func(*Req) error) error,
)

RetryStreamingClientStream will repeatedly call handler with the stream returned by "rpc" until handler returns nil or the context is cancelled.

If the stream errors, it will be closed and a new call will be issued.

func Serve

func Serve(ctx context.Context, listen *url.URL, options ...Option) error

Serve starts a HTTP and Connect gRPC server with sane defaults for FTL.

Blocks until the context is cancelled.

func VerbFromContext

func VerbFromContext(ctx context.Context) (*schema.VerbRef, bool)

VerbFromContext returns the current module.verb of the current request.

func VerbsFromContext

func VerbsFromContext(ctx context.Context) ([]*schema.VerbRef, bool)

VerbsFromContext returns the module.verb chain of the current request.

func Wait

func Wait(ctx context.Context, retry backoff.Backoff, client Pingable) error

Wait for a client to become available.

This will repeatedly call Ping() every 100ms until the service becomes ready. TODO: This will probably need to be smarter at some point.

If "ctx" is cancelled this will return ctx.Err()

func WithDirectRouting

func WithDirectRouting(ctx context.Context) context.Context

WithDirectRouting ensures any hops in Verb routing do not redirect.

This is used so that eg. calls from Drives do not create recursive loops when calling back to the Agent.

func WithRequestName added in v0.12.0

func WithRequestName(ctx context.Context, key model.RequestName) context.Context

WithRequestName adds the request Key to the context.

func WithVerbs

func WithVerbs(ctx context.Context, verbs []*schema.VerbRef) context.Context

WithVerbs adds the module.verb chain from the current request to the context.

Types

type ClientFactory

type ClientFactory[Client Pingable] func(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) Client

ClientFactory is a function that creates a new client and is typically one of the New*Client functions generated by protoc-gen-connect-go.

type GRPCServerConstructor

type GRPCServerConstructor[Iface Pingable] func(svc Iface, opts ...connect.HandlerOption) (string, http.Handler)

type Option

type Option func(*optionsBundle)

func GRPC

func GRPC[Iface, Impl Pingable](constructor GRPCServerConstructor[Iface], impl Impl, options ...connect.HandlerOption) Option

GRPC is a convenience function for registering a GRPC server with default options. TODO(aat): Do we need pingable here?

func HTTP

func HTTP(prefix string, handler http.Handler) Option

HTTP adds a HTTP route to the server.

func RawGRPC

func RawGRPC[Iface, Impl any](constructor RawGRPCServerConstructor[Iface], impl Impl, options ...connect.HandlerOption) Option

RawGRPC is a convenience function for registering a GRPC server with default options without Pingable.

type Pingable

type Pingable interface {
	Ping(context.Context, *connect.Request[ftlv1.PingRequest]) (*connect.Response[ftlv1.PingResponse], error)
}

type RawGRPCServerConstructor

type RawGRPCServerConstructor[Iface any] func(svc Iface, opts ...connect.HandlerOption) (string, http.Handler)

type Server

type Server struct {
	Bind   *pubsub.Topic[*url.URL] // Will be updated with the actual bind address.
	Server *http.Server
	// contains filtered or unexported fields
}

func NewServer

func NewServer(ctx context.Context, listen *url.URL, options ...Option) (*Server, error)

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Serve runs the server, updating .Bind with the actual bind address.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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