Documentation ¶
Overview ¶
Package grpckit is helper package for gRPC
Index ¶
- func DefaultGRPCErrorHandler(err error) *spb.Status
- func ErrorResponseWriterInterceptor(errHandler GRPCErrorHandler) grpc.UnaryServerInterceptor
- func LoggerInterceptor() grpc.UnaryServerInterceptor
- func RequestIDInterceptor(rIDProvider RequestIDProvider) grpc.UnaryServerInterceptor
- func RequestTimeoutInterceptor(t time.Duration) grpc.UnaryServerInterceptor
- func Run(s *grpc.Server, cfg *RuntimeConfig)
- func RunWithContext(appCtx context.Context, s *grpc.Server, cfg *RuntimeConfig)
- type GRPCErrorHandler
- type HealthCheckFunc
- type HealthCheckServer
- type RequestIDProvider
- type RuntimeConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultGRPCErrorHandler ¶
DefaultGRPCErrorHandler provides default error to standard protobuff status.
func ErrorResponseWriterInterceptor ¶
func ErrorResponseWriterInterceptor(errHandler GRPCErrorHandler) grpc.UnaryServerInterceptor
ErrorResponseWriterInterceptor writes grpc status based on error found from upstream call.
func LoggerInterceptor ¶
func LoggerInterceptor() grpc.UnaryServerInterceptor
LoggerInterceptor adds logger to request context.Context & logs the upstream call output.
func RequestIDInterceptor ¶
func RequestIDInterceptor(rIDProvider RequestIDProvider) grpc.UnaryServerInterceptor
RequestIDInterceptor add request id to incoming request if it doesn't exists yet.
func RequestTimeoutInterceptor ¶
func RequestTimeoutInterceptor(t time.Duration) grpc.UnaryServerInterceptor
RequestTimeoutInterceptor adds timeout to incoming request if it doesn't exists yet.
func Run ¶
func Run(s *grpc.Server, cfg *RuntimeConfig)
Run grpc server with health check, creating new app context.
func RunWithContext ¶
func RunWithContext(appCtx context.Context, s *grpc.Server, cfg *RuntimeConfig)
RunWithContext runs grpc server with health check using existing background context.
Types ¶
type GRPCErrorHandler ¶
GRPCErrorHandler transforms error to valid grpc standard protobuff status.
type HealthCheckFunc ¶
HealthCheckFunc - health check template func.
type HealthCheckServer ¶
type HealthCheckServer struct { Serving bool // contains filtered or unexported fields }
HealthCheckServer is default grpc health check provider.
func NewHealthcheckServer ¶
func NewHealthcheckServer(hcFunc HealthCheckFunc) *HealthCheckServer
NewHealthcheckServer - factory.
func (*HealthCheckServer) Check ¶
func (s *HealthCheckServer) Check(ctx context.Context, _ *grpc_health_v1.HealthCheckRequest) (*grpc_health_v1.HealthCheckResponse, error)
Check - grpc_health_v1.Server impl.
func (*HealthCheckServer) Watch ¶
func (s *HealthCheckServer) Watch(_ *grpc_health_v1.HealthCheckRequest, server grpc_health_v1.Health_WatchServer) error
Watch - grpc_health_v1.Server impl.
type RequestIDProvider ¶
type RequestIDProvider interface {
NewRequestID() string
}
RequestIDProvider generates new request id for each requests.
func DefaultRequestIDProvider ¶
func DefaultRequestIDProvider() RequestIDProvider
DefaultRequestIDProvider generates shortuuid string for request id.
type RuntimeConfig ¶
type RuntimeConfig struct { ShutdownWaitDuration time.Duration `json:"shutdown_wait_duration,omitempty"` RequestTimeout time.Duration `json:"request_timeout,omitempty"` Port int `json:"port,omitempty"` Name string `json:"name,omitempty"` EnableReflection bool `json:"enable_reflection,omitempty"` HealthCheckFunc `json:"-"` }
RuntimeConfig defines runtime configuration for grpc service with health check.
func NewRuntimeConfig ¶
func NewRuntimeConfig(cfg config.KVStore, path string) *RuntimeConfig
NewRuntimeConfig returns *RuntimeConfig based on viper configuration with layout:
given config file contents: grpc: port: 8088 request-timeout: 10s shutdown-wait-duration: 3s reflection-enabled: true call using `grpckit.NewRuntimeConfig(v, "grpc")`.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package grpcapmkit provides grpc-apm related helper
|
Package grpcapmkit provides grpc-apm related helper |