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 ¶
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 ¶
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)
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 ¶
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 ¶
WithTLS enables TLS for the gRPC connection to the backend. If config is nil, uses system default TLS config.
func WithWSOriginPatterns ¶
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).