gateway

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package gateway provides an HTTP handler for the EventService using gRPC-Gateway.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GuardedService added in v0.3.0

type GuardedService interface {
	ApplyGuard(ctx context.Context, action string) (context.Context, error)
}

GuardedService is the optional interface an EventServiceServer may implement to participate in SecurityGuard enforcement when invoked directly (bypassing the gRPC interceptors). In-process gateway handlers call ApplyGuard before delegating so that authentication and authorization are not silently skipped.

type Handler

type Handler struct {
	http.Handler
	// contains filtered or unexported fields
}

Handler is an HTTP handler for the EventService gateway. For handlers created by NewHandler, Close releases the underlying gRPC connection. For handlers created by NewInProcessHandler, Close is a no-op.

func NewHandler

func NewHandler(ctx context.Context, grpcAddr string, opts ...Option) (*Handler, error)

NewHandler creates a Handler that proxies to the gRPC service. The handler can be mounted on any HTTP router.

Example:

handler, _ := gateway.NewHandler(ctx, "localhost:9090", gateway.WithInsecure())
defer handler.Close()
http.Handle("/", handler)

func NewInProcessHandler

func NewInProcessHandler(ctx context.Context, svc eventpb.EventServiceServer, opts ...Option) (*Handler, error)

NewInProcessHandler creates a handler that calls the service directly without going through a network connection.

Example:

svc := service.NewService(transport, service.WithSecurityGuard(guard))
handler, _ := gateway.NewInProcessHandler(ctx, svc)
http.Handle("/", handler)

func (*Handler) Close

func (h *Handler) Close() error

Close releases resources held by the handler.

type Option

type Option func(*options)

Option configures the gateway handler.

func WithDialOptions

func WithDialOptions(opts ...grpc.DialOption) Option

WithDialOptions appends additional gRPC dial options. Only used with NewHandler (not NewInProcessHandler).

func WithHeartbeatInterval

func WithHeartbeatInterval(d time.Duration) Option

WithHeartbeatInterval sets the interval for heartbeat messages on WebSocket and SSE connections. Default is 30 seconds.

func WithInsecure

func WithInsecure() Option

WithInsecure explicitly enables insecure connections (no TLS). This should only be used for development/testing.

func WithMuxOptions

func WithMuxOptions(opts ...runtime.ServeMuxOption) Option

WithMuxOptions sets the ServeMux options for the gateway.

func WithTLS

func WithTLS(config *tls.Config) Option

WithTLS enables TLS for the gRPC connection to the backend. If config is nil, uses system default TLS config.

func WithWSOriginPatterns

func WithWSOriginPatterns(patterns ...string) Option

WithWSOriginPatterns sets the allowed WebSocket origin patterns. Patterns are matched against the Origin header (e.g., "example.com", "*.example.com"). If empty, all origins are allowed (insecure).

Jump to

Keyboard shortcuts

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