Documentation
¶
Index ¶
- Constants
- Variables
- func FieldMaskFromRequestBody(r io.Reader, msg proto.Message) (*fieldmask.FieldMask, error)
- func HTTPPathPattern(ctx context.Context) (string, bool)
- func HTTPStatusFromCode(code codes.Code) int
- func NewContextWithServerTransportStream(ctx context.Context, s grpc.ServerStream, method string) context.Context
- func NewServerMetadataContext(ctx context.Context, md ServerMetadata) context.Context
- func RPCMethod(ctx context.Context) (string, bool)
- func TransparentHandler(cli grpc.ClientConnInterface, inType, outType protoreflect.MessageType, ...) grpc.StreamHandler
- type AnnotateContextOption
- type Backend
- type Codec
- type CodecJSON
- func (c CodecJSON) Marshal(v any) ([]byte, error)
- func (c CodecJSON) MarshalAppend(b []byte, v any) ([]byte, error)
- func (CodecJSON) Name() string
- func (c CodecJSON) ReadNext(b []byte, r io.Reader, limit int) ([]byte, int, error)
- func (c CodecJSON) Unmarshal(data []byte, v any) error
- func (c CodecJSON) WriteNext(w io.Writer, b []byte) (int, error)
- type CodecProto
- func (c CodecProto) Marshal(v any) ([]byte, error)
- func (c CodecProto) MarshalAppend(b []byte, v any) ([]byte, error)
- func (CodecProto) Name() string
- func (c CodecProto) ReadNext(b []byte, r io.Reader, limit int) ([]byte, int, error)
- func (CodecProto) Unmarshal(data []byte, v any) error
- func (c CodecProto) WriteNext(w io.Writer, b []byte) (int, error)
- type Compressor
- type Dispatcher
- func (d *Dispatcher) Dispatch(ctx context.Context, backend Backend, frontend FrontendStream, op *Operation, ...) (header, trailer metadata.MD, err error)
- func (d *Dispatcher) DispatchFrontend(ctx context.Context, backend Backend, frontend FrontendStream, op *Operation) (header, trailer metadata.MD, err error)
- type FrontendStream
- type Gateway
- type GrpcMethod
- type MatchOperation
- type MethodHandler
- type MethodRoute
- type Mux
- func (m *Mux) Dispatch(ctx context.Context, frontend FrontendStream, op *Operation, in any) (metadata.MD, metadata.MD, error)
- func (m *Mux) DispatchFrontend(ctx context.Context, frontend FrontendStream, op *Operation) (metadata.MD, metadata.MD, error)
- func (m *Mux) Err() error
- func (m *Mux) GRPCPassthroughStreamHandler() grpc.StreamHandler
- func (m *Mux) GRPCServerOptions(extra ...grpc.ServerOption) []grpc.ServerOption
- func (m *Mux) GetOperation(operation string) *GrpcMethod
- func (m *Mux) GetOperationByName(name string) *GrpcMethod
- func (m *Mux) GetRouteMethods() []RouteOperation
- func (m *Mux) Handler(ctx fiber.Ctx) error
- func (m *Mux) Invoke(ctx context.Context, method string, args, reply any, opts ...grpc.CallOption) error
- func (m *Mux) MatchOperation(method, path string) (r result.Result[*MatchOperation])
- func (m *Mux) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, ...) (grpc.ClientStream, error)
- func (m *Mux) RegisterProxy(sd *grpc.ServiceDesc, proxy lava.GrpcRouter, cli grpc.ClientConnInterface)
- func (m *Mux) RegisterService(sd *grpc.ServiceDesc, ss any)
- func (m *Mux) Routes() []MethodRoute
- func (m *Mux) ServeHTTP(writer http.ResponseWriter, request *http.Request)
- func (m *Mux) SetRequestDecoder(name protoreflect.FullName, f func(ctx fiber.Ctx, msg proto.Message) error)
- func (m *Mux) SetResponseEncoder(name protoreflect.FullName, f func(ctx fiber.Ctx, msg proto.Message) error)
- func (m *Mux) SetStreamInterceptor(interceptor grpc.StreamServerInterceptor)
- func (m *Mux) SetUnaryInterceptor(interceptor grpc.UnaryServerInterceptor)
- func (m *Mux) WebSocketHandler(opts ...WSOption) http.Handler
- type MuxOption
- type Operation
- type PathFieldVar
- type RouteOperation
- type ServerMetadata
- type ServerTransportStream
- func (s *ServerTransportStream) Header() metadata.MD
- func (s *ServerTransportStream) Method() string
- func (s *ServerTransportStream) SendHeader(md metadata.MD) error
- func (s *ServerTransportStream) SetHeader(md metadata.MD) error
- func (s *ServerTransportStream) SetTrailer(md metadata.MD) error
- func (s *ServerTransportStream) Trailer() metadata.MD
- type StreamDirector
- type StreamHandler
- type WSConfig
- type WSOption
Constants ¶
const MetadataHeaderPrefix = "Grpc-Metadata-"
MetadataHeaderPrefix is the http prefix that represents custom metadata parameters to or from a gRPC call.
const MetadataPrefix = "grpcgateway-"
MetadataPrefix is prepended to permanent HTTP header keys (as specified by the IANA) when added to the gRPC context.
const MetadataTrailerPrefix = "Grpc-Trailer-"
MetadataTrailerPrefix is prepended to gRPC metadata as it is converted to HTTP headers in a response handled by grpc-gateway
Variables ¶
var DefaultContextTimeout = 0 * time.Second
DefaultContextTimeout is used for gRPC call context.WithTimeout whenever a Grpc-Timeout inbound header isn't present. If the value is 0 the sent `context` will not have a timeout.
Functions ¶
func FieldMaskFromRequestBody ¶
FieldMaskFromRequestBody creates a FieldMask printing all complete paths from the JSON body.
func HTTPPathPattern ¶
HTTPPathPattern returns the HTTP path pattern string relating to the HTTP handler, if one exists. The format of the returned string is defined by the google.api.http path template type.
func HTTPStatusFromCode ¶
HTTPStatusFromCode converts a gRPC error code into the corresponding HTTP response status. See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
func NewServerMetadataContext ¶
func NewServerMetadataContext(ctx context.Context, md ServerMetadata) context.Context
NewServerMetadataContext creates a new context with ServerMetadata
func RPCMethod ¶
RPCMethod returns the method string for the server context. The returned string is in the format of "/package.service/method".
func TransparentHandler ¶
func TransparentHandler(cli grpc.ClientConnInterface, inType, outType protoreflect.MessageType, opts ...grpc.CallOption) grpc.StreamHandler
Types ¶
type AnnotateContextOption ¶
func WithHTTPPathPattern ¶
func WithHTTPPathPattern(pattern string) AnnotateContextOption
type Backend ¶ added in v2.2.0
type Backend = grpc.ClientConnInterface
Backend is the unified gRPC dispatch target. Mux implements this via in-process handlers and optional remote proxy clients.
type Codec ¶
type Codec interface {
encoding.Codec
// MarshalAppend appends the marshaled form of v to b and returns the result.
MarshalAppend([]byte, any) ([]byte, error)
}
Codec defines the interface used to encode and decode messages.
type CodecJSON ¶
type CodecJSON struct {
protojson.MarshalOptions
protojson.UnmarshalOptions
}
CodecJSON is a Codec implementation with protobuf json format.
type CodecProto ¶
type CodecProto struct {
proto.MarshalOptions
}
CodecProto is a Codec implementation with protobuf binary format.
func (CodecProto) MarshalAppend ¶
func (c CodecProto) MarshalAppend(b []byte, v any) ([]byte, error)
func (CodecProto) Name ¶
func (CodecProto) Name() string
Name == "proto" overwritting internal proto codec
type Compressor ¶
type Compressor interface {
encoding.Compressor
}
Compressor is used to compress and decompress messages. Based on grpc/encoding.
type Dispatcher ¶ added in v2.2.0
type Dispatcher struct{}
Dispatcher routes frontend streams to a Backend, handling unary, server-streaming, client-streaming, and bidi modes.
func NewDispatcher ¶ added in v2.2.0
func NewDispatcher() *Dispatcher
func (*Dispatcher) Dispatch ¶ added in v2.2.0
func (d *Dispatcher) Dispatch( ctx context.Context, backend Backend, frontend FrontendStream, op *Operation, in any, ) (header, trailer metadata.MD, err error)
Dispatch connects a frontend stream to the backend for the given operation. For unary and server-streaming RPCs, in must already be populated by the frontend (RecvMsg on the request message).
func (*Dispatcher) DispatchFrontend ¶ added in v2.2.0
func (d *Dispatcher) DispatchFrontend( ctx context.Context, backend Backend, frontend FrontendStream, op *Operation, ) (header, trailer metadata.MD, err error)
DispatchFrontend drives a frontend grpc.ServerStream end-to-end. For unary and server-streaming RPCs it pre-reads the request message via RecvMsg before dispatching; client-streaming and bidi read inside the pump. This is the shared entrypoint for frontends whose request surface is already a grpc.ServerStream (native gRPC passthrough, websocket, zrpc).
type FrontendStream ¶ added in v2.2.0
type FrontendStream = grpc.ServerStream
FrontendStream is the protocol-neutral request/response surface exposed by each gateway frontend (HTTP, gRPC-Web, WebSocket, native gRPC).
type Gateway ¶
type Gateway interface {
grpc.ClientConnInterface
SetUnaryInterceptor(interceptor grpc.UnaryServerInterceptor)
SetStreamInterceptor(interceptor grpc.StreamServerInterceptor)
SetRequestDecoder(protoreflect.FullName, func(ctx fiber.Ctx, msg proto.Message) error)
SetResponseEncoder(protoreflect.FullName, func(ctx fiber.Ctx, msg proto.Message) error)
RegisterService(sd *grpc.ServiceDesc, ss any)
GetOperation(operation string) *GrpcMethod
Handler(fiber.Ctx) error
ServeHTTP(http.ResponseWriter, *http.Request)
GetRouteMethods() []RouteOperation
}
type GrpcMethod ¶
type GrpcMethod struct {
Srv any
SrvDesc *grpc.ServiceDesc
GrpcMethodDesc *grpc.MethodDesc
GrpcStreamDesc *grpc.StreamDesc
MethodDesc protoreflect.MethodDescriptor
GrpcFullMethod string
Meta *lavapbv1.RpcMeta
}
type MatchOperation ¶
type MatchOperation = routertree.MatchOperation
func GetRouterTarget ¶
func GetRouterTarget(mux *Mux, kind, path string) (*MatchOperation, error)
type MethodHandler ¶
type MethodRoute ¶ added in v2.2.0
MethodRoute describes a registered gRPC method for external protocol bridges.
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
func (*Mux) Dispatch ¶ added in v2.2.0
func (m *Mux) Dispatch(ctx context.Context, frontend FrontendStream, op *Operation, in any) (metadata.MD, metadata.MD, error)
Dispatch routes a frontend stream to the Mux backend.
func (*Mux) DispatchFrontend ¶ added in v2.2.0
func (m *Mux) DispatchFrontend(ctx context.Context, frontend FrontendStream, op *Operation) (metadata.MD, metadata.MD, error)
DispatchFrontend drives a frontend stream end-to-end through the dispatcher.
func (*Mux) GRPCPassthroughStreamHandler ¶ added in v2.2.0
func (m *Mux) GRPCPassthroughStreamHandler() grpc.StreamHandler
GRPCPassthroughStreamHandler returns a stream handler suitable for grpc.UnknownServiceHandler. Native gRPC clients connect to a *grpc.Server configured with this handler; each RPC is forwarded to the Mux backend (inprocgrpc local handlers or remote proxies) through the unified Dispatcher, so unary, server-stream, client-stream, and bidi all behave correctly.
Register services only on the Mux (RegisterService / RegisterProxy); do not register the same implementations again on the outer grpc.Server.
func (*Mux) GRPCServerOptions ¶ added in v2.2.0
func (m *Mux) GRPCServerOptions(extra ...grpc.ServerOption) []grpc.ServerOption
GRPCServerOptions returns server options that enable native gRPC passthrough through this Mux. Append to grpc.NewServer or grpcbuilder.Config.Build opts.
func (*Mux) GetOperation ¶
func (m *Mux) GetOperation(operation string) *GrpcMethod
func (*Mux) GetOperationByName ¶
func (m *Mux) GetOperationByName(name string) *GrpcMethod
func (*Mux) GetRouteMethods ¶
func (m *Mux) GetRouteMethods() []RouteOperation
func (*Mux) MatchOperation ¶
func (m *Mux) MatchOperation(method, path string) (r result.Result[*MatchOperation])
func (*Mux) NewStream ¶
func (m *Mux) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error)
func (*Mux) RegisterProxy ¶
func (m *Mux) RegisterProxy(sd *grpc.ServiceDesc, proxy lava.GrpcRouter, cli grpc.ClientConnInterface)
func (*Mux) RegisterService ¶
func (m *Mux) RegisterService(sd *grpc.ServiceDesc, ss any)
RegisterService satisfies grpc.ServiceRegistrar for generated service code hooks.
func (*Mux) Routes ¶ added in v2.2.0
func (m *Mux) Routes() []MethodRoute
Routes returns registered gRPC full methods for external bridges (e.g. zrpc).
func (*Mux) SetRequestDecoder ¶
func (*Mux) SetResponseEncoder ¶
func (*Mux) SetStreamInterceptor ¶
func (m *Mux) SetStreamInterceptor(interceptor grpc.StreamServerInterceptor)
SetStreamInterceptor configures the in-process channel to use the given server interceptor for streaming RPCs when dispatching.
func (*Mux) SetUnaryInterceptor ¶
func (m *Mux) SetUnaryInterceptor(interceptor grpc.UnaryServerInterceptor)
func (*Mux) WebSocketHandler ¶ added in v2.2.0
WebSocketHandler returns an http.Handler that bridges websocket clients to the registered gRPC handlers. It uses coder/websocket, so it must be served by a standard net/http server (it cannot run on the fasthttp/fiber stack).
The request path is interpreted as the gRPC full method name, e.g. "/pkg.v1.Service/Method". The wire format defaults to protojson (text frames) and can be switched to protobuf (binary frames) via the "?encoding=proto" query parameter or the "grpc-ws-proto" subprotocol.
type Operation ¶ added in v2.2.0
type Operation struct {
FullMethod string
InputType protoreflect.MessageType
OutputType protoreflect.MessageType
StreamDesc *grpc.StreamDesc // nil for unary RPCs
Meta *lavapbv1.RpcMeta
}
Operation describes a registered RPC method and its schema.
type PathFieldVar ¶
type PathFieldVar = routertree.PathFieldVar
type RouteOperation ¶
type RouteOperation = routertree.RouteOperation
type ServerMetadata ¶
ServerMetadata consists of metadata sent from gRPC server.
func ServerMetadataFromContext ¶
func ServerMetadataFromContext(ctx context.Context) (md ServerMetadata, ok bool)
ServerMetadataFromContext returns the ServerMetadata in ctx
type ServerTransportStream ¶
type ServerTransportStream struct {
// contains filtered or unexported fields
}
ServerTransportStream implements grpc.ServerTransportStream. It should only be used by the generated files to support grpc.SendHeader outside of gRPC server use.
func (*ServerTransportStream) Header ¶
func (s *ServerTransportStream) Header() metadata.MD
Header returns the header metadata of the stream.
func (*ServerTransportStream) Method ¶
func (s *ServerTransportStream) Method() string
Method returns the method for the stream.
func (*ServerTransportStream) SendHeader ¶
func (s *ServerTransportStream) SendHeader(md metadata.MD) error
SendHeader sets the header metadata.
func (*ServerTransportStream) SetHeader ¶
func (s *ServerTransportStream) SetHeader(md metadata.MD) error
SetHeader sets the header metadata.
func (*ServerTransportStream) SetTrailer ¶
func (s *ServerTransportStream) SetTrailer(md metadata.MD) error
SetTrailer sets the trailer metadata.
func (*ServerTransportStream) Trailer ¶
func (s *ServerTransportStream) Trailer() metadata.MD
Trailer returns the cached trailer metadata.
type StreamDirector ¶
type StreamHandler ¶
type StreamHandler = grpc.StreamHandler
type WSConfig ¶ added in v2.2.0
type WSConfig struct {
// OriginPatterns are passed to coder/websocket AcceptOptions.OriginPatterns.
// When empty and InsecureSkipVerify is false, only same-origin connections are allowed.
OriginPatterns []string
// InsecureSkipVerify disables origin verification. Use only in development.
InsecureSkipVerify bool
// Subprotocols advertised during the handshake. Defaults to grpc-ws-json and grpc-ws-proto.
Subprotocols []string
}
WSConfig holds websocket frontend settings for production wiring.
type WSOption ¶ added in v2.2.0
type WSOption func(*wsOptions)
WSOption configures the websocket frontend.
func WSOptionsFromConfig ¶ added in v2.2.0
WSOptionsFromConfig builds WSOption values from WSConfig.
func WithWSInsecureSkipVerify ¶ added in v2.2.0
func WithWSInsecureSkipVerify() WSOption
WithWSInsecureSkipVerify disables websocket origin verification.
func WithWSOriginPatterns ¶ added in v2.2.0
WithWSOriginPatterns sets allowed origin patterns for the websocket handshake.
func WithWSSubprotocols ¶ added in v2.2.0
WithWSSubprotocols sets the advertised websocket subprotocols.