Documentation
¶
Index ¶
- func CreateGatewayMux() *runtime.ServeMux
- func DefaultHealthCheckers() map[string]HealthChecker
- func GatewayHealthMiddleware() echo.MiddlewareFunc
- func LogGatewayRoutes(basePath string, services []string)
- func MountGatewayOnEcho(e *echo.Echo, gatewayMux *runtime.ServeMux, basePath string)
- func MountGatewayWithStripPrefix(e *echo.Echo, gatewayMux *runtime.ServeMux, mountPath, stripPrefix string)
- func SetupGatewayForH2C(ctx context.Context, gatewayMux *runtime.ServeMux, ...) error
- func SetupGatewayForSeparate(ctx context.Context, gatewayMux *runtime.ServeMux, grpcEndpoint string) error
- func Start(port string, serviceRegistrar func(*grpc.Server), opts ...Option) error
- func StartH2C(port string, serviceRegistrar func(*grpc.Server), opts ...Option) error
- func StartSeparate(grpcPort, httpPort string, serviceRegistrar func(*grpc.Server), opts ...Option) error
- type GatewayRoute
- type HealthCheckResult
- type HealthChecker
- type HealthManager
- func (hm *HealthManager) CheckHealth() map[string]HealthCheckResult
- func (h *HealthManager) CreateEchoHealthHandler(checkName string) echo.HandlerFunc
- func (hm *HealthManager) CreateHealthHandlers(basePath string) map[string]http.HandlerFunc
- func (h *HealthManager) EchoHealthCheckMiddleware() echo.MiddlewareFunc
- func (hm *HealthManager) GetOverallStatus() HealthStatus
- func (hm *HealthManager) RegisterCheck(name string, checker HealthChecker)
- func (h *HealthManager) RegisterEchoHealthChecks(e *echo.Echo, basePath string)
- func (h *HealthManager) RegisterEchoIndividualHealthChecks(e *echo.Echo, basePath string)
- func (hm *HealthManager) RemoveCheck(name string)
- func (hm *HealthManager) SetEnabled(enabled bool)
- type HealthStatus
- type MetricsManager
- func (mm *MetricsManager) CreateMetricsHandler() http.Handler
- func (mm *MetricsManager) DecrementGRPCConnections()
- func (mm *MetricsManager) DecrementHTTPRequests()
- func (m *MetricsManager) EchoMetricsMiddleware() echo.MiddlewareFunc
- func (m *MetricsManager) EchoUptimeMiddleware() echo.MiddlewareFunc
- func (mm *MetricsManager) GetRegistry() *prometheus.Registry
- func (mm *MetricsManager) HTTPMetricsMiddleware(next http.Handler) http.Handler
- func (mm *MetricsManager) IncrementGRPCConnections()
- func (mm *MetricsManager) IncrementHTTPRequests()
- func (mm *MetricsManager) RecordGRPCRequest(method string, statusCode string, duration time.Duration, ...)
- func (mm *MetricsManager) RecordHTTPRequest(method, path string, statusCode int, duration time.Duration, ...)
- func (m *MetricsManager) RegisterEchoMetrics(e *echo.Echo, path string)
- func (mm *MetricsManager) UpdateUptime()
- type Option
- func WithCORS() Option
- func WithConnectionTimeouts(idle, age, grace time.Duration) Option
- func WithEchoConfigurer(fn func(*echo.Echo)) Option
- func WithGRPCConfigurer(fn func(*grpc.Server)) Option
- func WithGRPCPort(port string) Option
- func WithGatewayBasePath(path string) Option
- func WithH2CMode() Option
- func WithHTTPPort(port string) Option
- func WithHealthCheck() Option
- func WithHealthPath(path string) Option
- func WithIdleTimeout(d time.Duration) Option
- func WithLogging() Option
- func WithMaxConnectionAge(d time.Duration) Option
- func WithMaxConnectionAgeGrace(d time.Duration) Option
- func WithMaxConnectionIdle(d time.Duration) Option
- func WithMetrics() Option
- func WithMetricsPath(path string) Option
- func WithMiddleware(mw ...echo.MiddlewareFunc) Option
- func WithOTelConfig(cfg *otel.Config) Option
- func WithRateLimit(rps float64) Option
- func WithReadTimeout(d time.Duration) Option
- func WithReflection() Option
- func WithSeparateMode(grpcPort, httpPort string) Option
- func WithServiceRegistrar(fn func(*grpc.Server)) Option
- func WithShutdownHandler(fn func() error) Option
- func WithShutdownTimeout(d time.Duration) Option
- func WithTLS(certFile, keyFile string) Option
- func WithWriteTimeout(d time.Duration) Option
- func WithoutHealthCheck() Option
- func WithoutLogging() Option
- func WithoutMetrics() Option
- func WithoutReflection() Option
- type Server
- type ServerMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateGatewayMux ¶
CreateGatewayMux creates a new gateway mux with standard configuration
func DefaultHealthCheckers ¶
func DefaultHealthCheckers() map[string]HealthChecker
DefaultHealthCheckers returns a set of default health checkers
func GatewayHealthMiddleware ¶
func GatewayHealthMiddleware() echo.MiddlewareFunc
GatewayHealthMiddleware adds health monitoring for gateway routes
func LogGatewayRoutes ¶
LogGatewayRoutes logs information about mounted gateway routes
func MountGatewayOnEcho ¶
MountGatewayOnEcho mounts a gRPC gateway mux onto Echo under a base path
func MountGatewayWithStripPrefix ¶
func MountGatewayWithStripPrefix(e *echo.Echo, gatewayMux *runtime.ServeMux, mountPath, stripPrefix string)
MountGatewayWithStripPrefix mounts gateway with path prefix stripping
func SetupGatewayForH2C ¶
func SetupGatewayForH2C(ctx context.Context, gatewayMux *runtime.ServeMux, serviceRegistrar func(*grpc.Server), grpcServer *grpc.Server) error
SetupGatewayForH2C sets up gateway for H2C mode (server-side registration)
func SetupGatewayForSeparate ¶
func SetupGatewayForSeparate(ctx context.Context, gatewayMux *runtime.ServeMux, grpcEndpoint string) error
SetupGatewayForSeparate sets up gateway for separate mode (endpoint-based registration)
Types ¶
type GatewayRoute ¶
GatewayRoute represents a single gateway route configuration
type HealthCheckResult ¶
type HealthCheckResult struct {
Status HealthStatus `json:"status"`
Timestamp time.Time `json:"timestamp"`
Duration time.Duration `json:"duration"`
Details map[string]interface{} `json:"details,omitempty"`
Error string `json:"error,omitempty"`
}
HealthCheckResult represents the result of a health check
type HealthChecker ¶
type HealthChecker func() HealthCheckResult
HealthChecker defines the interface for health check functions
type HealthManager ¶
type HealthManager struct {
// contains filtered or unexported fields
}
HealthManager manages health checks for the server
func NewHealthManager ¶
func NewHealthManager() *HealthManager
NewHealthManager creates a new health manager
func (*HealthManager) CheckHealth ¶
func (hm *HealthManager) CheckHealth() map[string]HealthCheckResult
CheckHealth runs all registered health checks
func (*HealthManager) CreateEchoHealthHandler ¶
func (h *HealthManager) CreateEchoHealthHandler(checkName string) echo.HandlerFunc
CreateEchoHealthHandler creates a health check handler for specific checks
func (*HealthManager) CreateHealthHandlers ¶
func (hm *HealthManager) CreateHealthHandlers(basePath string) map[string]http.HandlerFunc
CreateHealthHandlers creates HTTP handlers for health check endpoints
func (*HealthManager) EchoHealthCheckMiddleware ¶
func (h *HealthManager) EchoHealthCheckMiddleware() echo.MiddlewareFunc
EchoHealthCheckMiddleware adds health check headers to responses
func (*HealthManager) GetOverallStatus ¶
func (hm *HealthManager) GetOverallStatus() HealthStatus
GetOverallStatus returns the overall health status
func (*HealthManager) RegisterCheck ¶
func (hm *HealthManager) RegisterCheck(name string, checker HealthChecker)
RegisterCheck registers a health check with the given name
func (*HealthManager) RegisterEchoHealthChecks ¶
func (h *HealthManager) RegisterEchoHealthChecks(e *echo.Echo, basePath string)
RegisterEchoHealthChecks registers health check endpoints with Echo
func (*HealthManager) RegisterEchoIndividualHealthChecks ¶
func (h *HealthManager) RegisterEchoIndividualHealthChecks(e *echo.Echo, basePath string)
RegisterEchoIndividualHealthChecks registers individual health check endpoints
func (*HealthManager) RemoveCheck ¶
func (hm *HealthManager) RemoveCheck(name string)
RemoveCheck removes a health check
func (*HealthManager) SetEnabled ¶
func (hm *HealthManager) SetEnabled(enabled bool)
SetEnabled enables or disables health checks
type HealthStatus ¶
type HealthStatus string
HealthStatus represents the status of a health check
const ( // HealthStatusUp indicates the service is healthy HealthStatusUp HealthStatus = "UP" // HealthStatusDown indicates the service is unhealthy HealthStatusDown HealthStatus = "DOWN" // HealthStatusUnknown indicates the health status is unknown HealthStatusUnknown HealthStatus = "UNKNOWN" )
type MetricsManager ¶
type MetricsManager struct {
// contains filtered or unexported fields
}
MetricsManager manages Prometheus metrics for the gRPC server
func NewMetricsManager ¶
func NewMetricsManager(namespace string) *MetricsManager
NewMetricsManager creates a new metrics manager
func (*MetricsManager) CreateMetricsHandler ¶
func (mm *MetricsManager) CreateMetricsHandler() http.Handler
CreateMetricsHandler creates an HTTP handler for the metrics endpoint
func (*MetricsManager) DecrementGRPCConnections ¶
func (mm *MetricsManager) DecrementGRPCConnections()
DecrementGRPCConnections decrements the active gRPC connections counter
func (*MetricsManager) DecrementHTTPRequests ¶
func (mm *MetricsManager) DecrementHTTPRequests()
DecrementHTTPRequests decrements the active HTTP requests counter
func (*MetricsManager) EchoMetricsMiddleware ¶
func (m *MetricsManager) EchoMetricsMiddleware() echo.MiddlewareFunc
EchoMetricsMiddleware returns Echo middleware that records HTTP metrics
func (*MetricsManager) EchoUptimeMiddleware ¶
func (m *MetricsManager) EchoUptimeMiddleware() echo.MiddlewareFunc
EchoUptimeMiddleware can be used to track server uptime via Echo
func (*MetricsManager) GetRegistry ¶
func (mm *MetricsManager) GetRegistry() *prometheus.Registry
GetRegistry returns the prometheus registry
func (*MetricsManager) HTTPMetricsMiddleware ¶
func (mm *MetricsManager) HTTPMetricsMiddleware(next http.Handler) http.Handler
HTTPMetricsMiddleware creates middleware for recording HTTP metrics
func (*MetricsManager) IncrementGRPCConnections ¶
func (mm *MetricsManager) IncrementGRPCConnections()
IncrementGRPCConnections increments the active gRPC connections counter
func (*MetricsManager) IncrementHTTPRequests ¶
func (mm *MetricsManager) IncrementHTTPRequests()
IncrementHTTPRequests increments the active HTTP requests counter
func (*MetricsManager) RecordGRPCRequest ¶
func (mm *MetricsManager) RecordGRPCRequest(method string, statusCode string, duration time.Duration, requestSize, responseSize int)
RecordGRPCRequest records metrics for a gRPC request
func (*MetricsManager) RecordHTTPRequest ¶
func (mm *MetricsManager) RecordHTTPRequest(method, path string, statusCode int, duration time.Duration, requestSize, responseSize int)
RecordHTTPRequest records metrics for an HTTP request
func (*MetricsManager) RegisterEchoMetrics ¶
func (m *MetricsManager) RegisterEchoMetrics(e *echo.Echo, path string)
RegisterEchoMetrics registers the Prometheus metrics endpoint with Echo
func (*MetricsManager) UpdateUptime ¶
func (mm *MetricsManager) UpdateUptime()
UpdateUptime updates the server uptime metric
type Option ¶
type Option func(*config)
Option is a functional option for configuring the server
func WithConnectionTimeouts ¶
WithConnectionTimeouts sets all gRPC connection timeout values
func WithEchoConfigurer ¶
WithEchoConfigurer sets the function to configure the Echo HTTP server
func WithGRPCConfigurer ¶
WithGRPCConfigurer sets the function to configure the gRPC server
func WithGatewayBasePath ¶
WithGatewayBasePath sets the base path for gRPC gateway routes
func WithH2CMode ¶
func WithH2CMode() Option
WithH2CMode sets the server to H2C mode (gRPC and HTTP on same port)
func WithHTTPPort ¶
WithHTTPPort sets the HTTP gateway port (only used in SeparateMode)
func WithHealthPath ¶
WithHealthPath sets the health check base path
func WithIdleTimeout ¶
WithIdleTimeout sets the HTTP server idle timeout
func WithMaxConnectionAge ¶
WithMaxConnectionAge sets the maximum connection age for gRPC
func WithMaxConnectionAgeGrace ¶
WithMaxConnectionAgeGrace sets the connection age grace period for gRPC
func WithMaxConnectionIdle ¶
WithMaxConnectionIdle sets the maximum connection idle time for gRPC
func WithMetricsPath ¶
WithMetricsPath sets the metrics endpoint path
func WithMiddleware ¶
func WithMiddleware(mw ...echo.MiddlewareFunc) Option
WithMiddleware adds custom Echo middleware
func WithOTelConfig ¶
WithOTelConfig sets the OpenTelemetry configuration for traces, metrics, and logs When set, the gRPC server will instrument with OTel instead of Prometheus
func WithRateLimit ¶
WithRateLimit enables rate limiting with the specified requests per second
func WithReadTimeout ¶
WithReadTimeout sets the HTTP server read timeout
func WithSeparateMode ¶
WithSeparateMode sets the server to separate mode with different ports for gRPC and HTTP
func WithServiceRegistrar ¶
WithServiceRegistrar sets the function to register gRPC services
func WithShutdownHandler ¶
WithShutdownHandler sets a custom shutdown handler
func WithShutdownTimeout ¶
WithShutdownTimeout sets the graceful shutdown timeout
func WithWriteTimeout ¶
WithWriteTimeout sets the HTTP server write timeout
func WithoutHealthCheck ¶
func WithoutHealthCheck() Option
WithoutHealthCheck disables health check endpoints
func WithoutMetrics ¶
func WithoutMetrics() Option
WithoutMetrics disables Prometheus metrics endpoint
func WithoutReflection ¶
func WithoutReflection() Option
WithoutReflection disables gRPC server reflection
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents the gRPC server and gateway
func (*Server) GetGRPCServer ¶
GetGRPCServer returns the underlying gRPC server
func (*Server) GetHealthManager ¶
func (s *Server) GetHealthManager() *HealthManager
GetHealthManager returns the health manager
func (*Server) GetMetricsManager ¶
func (s *Server) GetMetricsManager() *MetricsManager
GetMetricsManager returns the metrics manager
type ServerMode ¶
type ServerMode string
ServerMode defines the server operation mode
const ( // SeparateMode runs gRPC and HTTP servers on separate ports SeparateMode ServerMode = "separate" // H2CMode runs both gRPC and HTTP on a single port using HTTP/2 cleartext H2CMode ServerMode = "h2c" )