grpcgatewayx

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package grpcgatewayx contains runtime helpers for grpc-gateway generated *.gw.pb.go handlers.

Recommended Kernel pattern:

  • Use proto + google.api.http as the API contract.
  • Generate *.pb.go, *_grpc.pb.go and *.gw.pb.go.
  • Mount the generated gateway handler behind restx/gatewayx filters.
  • Keep business authz explicit in Gateway/BFF logic for complex routes.

grpc-gateway is best for REST/JSON-to-gRPC protocol translation. It is not a replacement for Kernel authn/authz/audit/session/gateway policy layers.

Package grpcgatewayx provides small helpers for mounting grpc-gateway generated reverse-proxy handlers inside Kernel gateway/BFF services.

It intentionally does not replace transportx/http or protoc-gen-go-http. Use it when a service is proto-first internally and wants to expose HTTP/JSON through grpc-gateway generated *.gw.pb.go files.

Index

Constants

View Source
const (
	HeaderRequestID       = "X-Request-Id"
	HeaderTraceID         = "X-Trace-Id"
	HeaderAuthzDecisionID = "X-Authz-Decision-Id"
	HeaderTraceparent     = "Traceparent"
	HeaderBaggage         = "Baggage"
)

Variables

This section is empty.

Functions

func DefaultMuxOptions

func DefaultMuxOptions(extra ...runtime.ServeMuxOption) []runtime.ServeMuxOption

DefaultMuxOptions returns gateway mux options for Kernel Gateway/BFF services. It propagates trusted contextx values into the outgoing gRPC context. It does not forward external Authorization or external authz-decision headers by default; Gateway code should create scoped/internal tokens explicitly.

func NewHandlerFromConn

func NewHandlerFromConn(ctx context.Context, conn *grpc.ClientConn, opts []runtime.ServeMuxOption, register RegisterHandlerFromConn) (http.Handler, error)

NewHandlerFromConn builds an http.Handler by registering grpc-gateway generated handlers against an existing gRPC ClientConn.

func NewHandlerFromEndpoint

func NewHandlerFromEndpoint(ctx context.Context, cfg HandlerConfig, register RegisterHandlerFromEndpoint) (http.Handler, error)

NewHandlerFromEndpoint builds an http.Handler by registering grpc-gateway generated handlers against a gRPC endpoint.

func NewServeMux

func NewServeMux(opts ...runtime.ServeMuxOption) *runtime.ServeMux

NewServeMux creates a grpc-gateway ServeMux. Exposed to keep generated registration explicit and testable.

Types

type HandlerConfig

type HandlerConfig struct {
	// Endpoint is the gRPC upstream address used by RegisterHandlerFromEndpoint,
	// for example "127.0.0.1:9000" or "skill-service:9000".
	Endpoint string

	// DialOptions are passed to grpc.DialContext by grpc-gateway. If empty,
	// WithInsecure defaults to true for local/internal development. Production
	// services should pass TLS/mTLS dial options explicitly.
	DialOptions []grpc.DialOption

	// MuxOptions are passed to runtime.NewServeMux.
	MuxOptions []runtime.ServeMuxOption

	// DialTimeout bounds grpc-gateway's initial connection attempt when using
	// RegisterHandlerFromEndpoint. Zero means no additional timeout is applied.
	DialTimeout time.Duration
}

HandlerConfig configures a grpc-gateway runtime mux.

type RegisterHandlerFromConn

type RegisterHandlerFromConn func(context.Context, *runtime.ServeMux, *grpc.ClientConn) error

RegisterHandlerFromConn matches grpc-gateway generated functions such as:

RegisterGreeterHandler(ctx, mux, conn)

Use this when the caller owns the gRPC ClientConn lifecycle.

type RegisterHandlerFromEndpoint

type RegisterHandlerFromEndpoint func(context.Context, *runtime.ServeMux, string, []grpc.DialOption) error

RegisterHandlerFromEndpoint matches grpc-gateway generated functions such as:

RegisterGreeterHandlerFromEndpoint(ctx, mux, endpoint, opts)

The generated function is emitted by protoc-gen-grpc-gateway into *.gw.pb.go.

Jump to

Keyboard shortcuts

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