gateway

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 9 Imported by: 0

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

View Source
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

type RegisterFunc func(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error

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)
}

Jump to

Keyboard shortcuts

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