grpckit

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package grpckit is helper package for gRPC

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultGRPCErrorHandler

func DefaultGRPCErrorHandler(err error) *spb.Status

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

type GRPCErrorHandler func(err error) *spb.Status

GRPCErrorHandler transforms error to valid grpc standard protobuff status.

type HealthCheckFunc

type HealthCheckFunc func(context.Context) error

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

Check - grpc_health_v1.Server impl.

func (*HealthCheckServer) Watch

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")`.

Directories

Path Synopsis
Package grpcapmkit provides grpc-apm related helper
Package grpcapmkit provides grpc-apm related helper

Jump to

Keyboard shortcuts

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