Documentation
¶
Overview ¶
Package gateway makes a grpc-gateway a first-class transport: it dials the local gRPC server (matching its transport security) and serves the generated REST handlers, either mounted on an existing HTTP server (New) or as its own controller-managed HTTP server on the "server.gateway" config block (Register).
Index ¶
Constants ¶
const ConfigPrefix = "server.gateway"
ConfigPrefix is the config block a gateway server reads (port, TLS) when run as its own service via Register. TLS falls back to the shared "server.tls".
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(ctx context.Context, cfg config.Containable, register RegisterFunc, opts ...Option) (http.Handler, error)
New builds a grpc-gateway handler ready to mount on an existing HTTP server. It dials the local gRPC server via grpc.DialLocal (so transport security matches the server's own config) and applies register to wire the handlers.
The returned handler is a *runtime.ServeMux. The underlying gRPC connection lives for the process; it is the standard pattern for an in-process gateway.
func Register ¶
func Register(ctx context.Context, id string, controller controls.Controllable, cfg config.Containable, logger logger.Logger, register RegisterFunc, opts ...Option) (*http.Server, error)
Register runs the gateway as its own controller-managed HTTP server on the "server.gateway" config block (TLS falling back to the shared "server.tls"), dialing the local gRPC server. It is the first-class form of New, a peer of grpc.Register and http.Register.
Types ¶
type Option ¶
type Option func(*options)
Option configures the gateway.
func WithDialOptions ¶
func WithDialOptions(opts ...grpc.DialOption) Option
WithDialOptions passes extra grpc.DialOption values to the connection the gateway opens to the gRPC server (transport security is set automatically).
func WithMuxOptions ¶
func WithMuxOptions(opts ...runtime.ServeMuxOption) Option
WithMuxOptions passes runtime.ServeMuxOption values to the gateway mux (e.g. a custom error handler or header matcher).
type RegisterFunc ¶
RegisterFunc registers the generated gateway handlers onto the mux, using a client connection to the gRPC server. It is the only gateway-specific code a caller writes, e.g.:
func(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return widgetv1.RegisterWidgetServiceHandler(ctx, mux, conn)
}