Documentation ¶
Index ¶
- Constants
- func ClientFromContext[Client Pingable](ctx context.Context) Client
- func ContextValuesMiddleware(ctx context.Context, handler http.Handler) http.HandlerFunc
- func ContextWithClient[Client Pingable](ctx context.Context, client Client) context.Context
- func DefaultClientOptions(level log.Level) []connect.ClientOption
- func DefaultHandlerOptions() []connect.HandlerOption
- func Dial[Client Pingable](factory ClientFactory[Client], baseURL string, errorLevel log.Level, ...) Client
- func GetHTTPClient(url string) *http.Client
- func InitialiseClients(authenticators map[string]string)
- func IsDirectRouted(ctx context.Context) bool
- func MetadataInterceptor(errorLevel log.Level) connect.Interceptor
- func RequestKeyFromContext(ctx context.Context) (optional.Option[model.RequestKey], error)
- func RetryStreamingClientStream[Req, Resp any](ctx context.Context, retry backoff.Backoff, ...)
- func RetryStreamingServerStream[Req, Resp any](ctx context.Context, retry backoff.Backoff, req *Req, ...)
- func Serve(ctx context.Context, listen *url.URL, options ...Option) error
- func VerbFromContext(ctx context.Context) (*schema.Ref, bool)
- func VerbsFromContext(ctx context.Context) ([]*schema.Ref, bool)
- func Wait(ctx context.Context, retry backoff.Backoff, client Pingable) error
- func WithDirectRouting(ctx context.Context) context.Context
- func WithRequestName(ctx context.Context, key model.RequestKey) context.Context
- func WithVerbs(ctx context.Context, verbs []*schema.Ref) context.Context
- type ClientFactory
- type GRPCServerConstructor
- type Option
- type Pingable
- type RawGRPCServerConstructor
- type Server
Constants ¶
const ShutdownGracePeriod = time.Second * 5
Variables ¶
This section is empty.
Functions ¶
func ClientFromContext ¶
ClientFromContext returns the given RPC client from the context, or panics.
func ContextValuesMiddleware ¶
ContextValuesMiddleware injects values from a Context into the request Context.
func ContextWithClient ¶
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 ¶
GetHTTPClient returns a HTTP client usable for the given URL.
func InitialiseClients ¶
InitialiseClients initialises global 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 ¶
IsDirectRouted returns true if the incoming request should be directly routed and never redirected.
func MetadataInterceptor ¶
func MetadataInterceptor(errorLevel log.Level) connect.Interceptor
MetadataInterceptor propagates FTL metadata through servers and clients.
"errorLevel" is the level at which errors will be logged
func RequestKeyFromContext ¶ added in v0.165.1
RequestKeyFromContext returns the request key from the context, if any.
TODO: Return an Option here instead of a bool.
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 an error or the context is cancelled.
If the stream errors, it will be closed and a new call will be issued.
func RetryStreamingServerStream ¶ added in v0.134.1
func RetryStreamingServerStream[Req, Resp any]( ctx context.Context, retry backoff.Backoff, req *Req, rpc func(context.Context, *connect.Request[Req]) (*connect.ServerStreamForClient[Resp], error), handler func(ctx context.Context, resp *Resp) error, )
RetryStreamingServerStream will repeatedly call handler with responses from the stream returned by "rpc" until handler returns an error or the context is cancelled.
func Serve ¶
Serve starts a HTTP and Connect gRPC server with sane defaults for FTL.
Blocks until the context is cancelled.
func VerbFromContext ¶
VerbFromContext returns the current module.verb of the current request.
func VerbsFromContext ¶
VerbsFromContext returns the module.verb chain of the current request.
func Wait ¶
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 ¶
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 ¶
WithRequestName adds the request key 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 Option ¶
type Option func(*serverOptions)
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 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.