grpcfx

package
v0.6.31 Latest Latest
Warning

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

Go to latest
Published: May 27, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

README

ajan/grpcfx

Overview

The grpcfx package provides a framework for building gRPC services with support for reflection, graceful shutdown, and integration with the dependency injection system.

Configuration

Configuration struct for the gRPC service:

type Config struct {
  Addr                    string        `conf:"addr"             default:":9090"`
  Reflection              bool          `conf:"reflection"       default:"true"`
  InitializationTimeout   time.Duration `conf:"init_timeout"     default:"25s"`
  GracefulShutdownTimeout time.Duration `conf:"shutdown_timeout" default:"5s"`
}

Example configuration:

config := &grpcfx.Config{
  Addr:                    ":50051",
  Reflection:              true,
  InitializationTimeout:   30 * time.Second,
  GracefulShutdownTimeout: 10 * time.Second,
}

Features

  • gRPC service setup and configuration
  • Server reflection support
  • Graceful shutdown handling
  • Integration with dependency injection
  • Configurable timeouts
  • Support for multiple services
  • Middleware support

API

GrpcService

The main component for gRPC service handling:

// Create a new gRPC service
service := grpcfx.NewGrpcService(config)

// Register your gRPC service implementations
pb.RegisterYourServiceServer(service.GetServer(), &YourServiceImpl{})

// Start the service
if err := service.Start(); err != nil {
  log.Fatal(err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoggingInterceptor

func LoggingInterceptor(logger *logfx.Logger) grpc.UnaryServerInterceptor

func MetricsInterceptor

func MetricsInterceptor(metrics *Metrics) grpc.UnaryServerInterceptor

Types

type Config

type Config struct {
	Addr                    string        `conf:"addr"             default:":9090"`
	Reflection              bool          `conf:"reflection"       default:"true"`
	InitializationTimeout   time.Duration `conf:"init_timeout"     default:"25s"`
	GracefulShutdownTimeout time.Duration `conf:"shutdown_timeout" default:"5s"`
}

type GrpcService

type GrpcService struct {
	InnerServer  *grpc.Server
	InnerMetrics *Metrics
	Config       *Config
	// contains filtered or unexported fields
}

func NewGrpcService

func NewGrpcService(config *Config, metricsProvider MetricsProvider, logger *logfx.Logger) *GrpcService

func (*GrpcService) RegisterService

func (gs *GrpcService) RegisterService(desc *grpc.ServiceDesc, impl any)

func (*GrpcService) Server

func (gs *GrpcService) Server() *grpc.Server

func (*GrpcService) Start

func (gs *GrpcService) Start(ctx context.Context) (func(), error)

type Metrics

type Metrics struct {
	RequestsTotal   *prometheus.CounterVec
	RequestDuration *prometheus.HistogramVec
	// contains filtered or unexported fields
}

func NewMetrics

func NewMetrics(metricsProvider MetricsProvider) *Metrics

type MetricsProvider

type MetricsProvider interface {
	GetRegistry() *prometheus.Registry
}

Jump to

Keyboard shortcuts

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