grpc

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package grpc is a generated GoMock package.

Package grpc pkg/grpc/server.go

Index

Constants

View Source
const (
	SecurityModeNone   models.SecurityMode = "none"
	SecurityModeSpiffe models.SecurityMode = "spiffe"
	SecurityModeMTLS   models.SecurityMode = "mtls"
)

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) logger.Logger

FromContext retrieves the logger from the context. If no logger is found, it returns a no-op test logger to prevent nil panics.

func GenerateTestCertificates

func GenerateTestCertificates(dir string) error

GenerateTestCertificates creates a CA, server, and client certificates in the specified directory. Generates: root.pem (CA), server.pem (server auth), client.pem (client auth).

func GetLogger

func GetLogger(ctx context.Context, defaultLogger logger.Logger) logger.Logger

GetLogger extracts the trace-aware logger from context, falls back to default if not found

func LoggingInterceptor

func LoggingInterceptor(log logger.Logger) grpc.UnaryServerInterceptor

LoggingInterceptor logs RPC calls and injects a trace-aware logger into the context.

func RecoveryInterceptor

func RecoveryInterceptor(log logger.Logger) grpc.UnaryServerInterceptor

RecoveryInterceptor handles panics in RPC handlers.

func RetryInterceptor

func RetryInterceptor(maxRetries int, log logger.Logger) grpc.UnaryClientInterceptor

RetryInterceptor provides basic retry logic.

Types

type CertificateManager

type CertificateManager struct {
	// contains filtered or unexported fields
}

CertificateManager helps manage TLS certificates.

func NewCertificateManager

func NewCertificateManager(config *models.SecurityConfig) *CertificateManager

func (*CertificateManager) EnsureCertificateDirectory

func (cm *CertificateManager) EnsureCertificateDirectory() error

func (*CertificateManager) ValidateCertificates

func (cm *CertificateManager) ValidateCertificates(mutual bool) error

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client manages a gRPC client connection.

func NewClient

func NewClient(ctx context.Context, cfg ClientConfig) (*Client, error)

NewClient creates a new gRPC client.

func (*Client) CheckHealth

func (c *Client) CheckHealth(ctx context.Context, service string) (bool, error)

CheckHealth performs a health check on the specified service.

func (*Client) Close

func (c *Client) Close() error

Close shuts down the client connection.

func (*Client) GetConnection

func (c *Client) GetConnection() *grpc.ClientConn

GetConnection returns the underlying gRPC connection.

type ClientConfig

type ClientConfig struct {
	Address          string
	SecurityProvider SecurityProvider
	MaxRetries       int
	Logger           logger.Logger
	DisableTelemetry bool
}

ClientConfig holds configuration for the gRPC client.

type MTLSProvider

type MTLSProvider struct {
	// contains filtered or unexported fields
}

MTLSProvider implements SecurityProvider with mutual TLS.

func NewMTLSProvider

func NewMTLSProvider(config *models.SecurityConfig, log logger.Logger) (*MTLSProvider, error)

NewMTLSProvider creates a new MTLSProvider with the given configuration.

func (*MTLSProvider) Close

func (p *MTLSProvider) Close() error

func (*MTLSProvider) GetClientCredentials

func (p *MTLSProvider) GetClientCredentials(_ context.Context) (grpc.DialOption, error)

func (*MTLSProvider) GetServerCredentials

func (p *MTLSProvider) GetServerCredentials(_ context.Context) (grpc.ServerOption, error)

type MockSecurityProvider

type MockSecurityProvider struct {
	// contains filtered or unexported fields
}

MockSecurityProvider is a mock of SecurityProvider interface.

func NewMockSecurityProvider

func NewMockSecurityProvider(ctrl *gomock.Controller) *MockSecurityProvider

NewMockSecurityProvider creates a new mock instance.

func (*MockSecurityProvider) Close

func (m *MockSecurityProvider) Close() error

Close mocks base method.

func (*MockSecurityProvider) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockSecurityProvider) GetClientCredentials

func (m *MockSecurityProvider) GetClientCredentials(ctx context.Context) (grpc.DialOption, error)

GetClientCredentials mocks base method.

func (*MockSecurityProvider) GetServerCredentials

func (m *MockSecurityProvider) GetServerCredentials(ctx context.Context) (grpc.ServerOption, error)

GetServerCredentials mocks base method.

type MockSecurityProviderMockRecorder

type MockSecurityProviderMockRecorder struct {
	// contains filtered or unexported fields
}

MockSecurityProviderMockRecorder is the mock recorder for MockSecurityProvider.

func (*MockSecurityProviderMockRecorder) Close

Close indicates an expected call of Close.

func (*MockSecurityProviderMockRecorder) GetClientCredentials

func (mr *MockSecurityProviderMockRecorder) GetClientCredentials(ctx any) *gomock.Call

GetClientCredentials indicates an expected call of GetClientCredentials.

func (*MockSecurityProviderMockRecorder) GetServerCredentials

func (mr *MockSecurityProviderMockRecorder) GetServerCredentials(ctx any) *gomock.Call

GetServerCredentials indicates an expected call of GetServerCredentials.

type NoSecurityProvider

type NoSecurityProvider struct {
	// contains filtered or unexported fields
}

NoSecurityProvider implements SecurityProvider with no security (development only).

func (*NoSecurityProvider) Close

func (*NoSecurityProvider) Close() error

func (*NoSecurityProvider) GetClientCredentials

func (*NoSecurityProvider) GetClientCredentials(context.Context) (grpc.DialOption, error)

func (*NoSecurityProvider) GetServerCredentials

func (*NoSecurityProvider) GetServerCredentials(context.Context) (grpc.ServerOption, error)

type SecurityProvider

type SecurityProvider interface {
	// GetClientCredentials returns credentials for client connections
	GetClientCredentials(ctx context.Context) (grpc.DialOption, error)

	// GetServerCredentials returns credentials for server connections
	GetServerCredentials(ctx context.Context) (grpc.ServerOption, error)

	// Close cleans up any resources
	Close() error
}

SecurityProvider defines the interface for gRPC security providers.

func NewSecurityProvider

func NewSecurityProvider(ctx context.Context, config *models.SecurityConfig, log logger.Logger) (SecurityProvider, error)

NewSecurityProvider creates the appropriate security provider based on mode.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server wraps a gRPC server with additional functionality.

func NewServer

func NewServer(addr string, log logger.Logger, opts ...ServerOption) *Server

NewServer creates a new gRPC server with the given configuration.

func (*Server) GetGRPCServer

func (s *Server) GetGRPCServer() *grpc.Server

GetGRPCServer returns the underlying gRPC server.

func (*Server) GetHealthCheck

func (s *Server) GetHealthCheck() *health.Server

GetHealthCheck returns the health server instance.

func (*Server) RegisterHealthServer

func (s *Server) RegisterHealthServer() error

RegisterHealthServer registers the health server if not already registered.

func (*Server) RegisterService

func (s *Server) RegisterService(desc *grpc.ServiceDesc, impl interface{})

RegisterService registers a service with the gRPC server.

func (*Server) Start

func (s *Server) Start() error

Start starts the gRPC server.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context)

Stop gracefully stops the gRPC server.

type ServerOption

type ServerOption func(*Server)

ServerOption is a function type that modifies Server configuration.

func WithMaxRecvSize

func WithMaxRecvSize(size int) ServerOption

WithMaxRecvSize sets the maximum receive message size.

func WithMaxSendSize

func WithMaxSendSize(size int) ServerOption

WithMaxSendSize sets the maximum send message size.

func WithServerOptions

func WithServerOptions(opt ...grpc.ServerOption) ServerOption

WithServerOptions adds gRPC server options.

func WithTelemetryDisabled added in v1.0.55

func WithTelemetryDisabled() ServerOption

WithTelemetryDisabled disables OpenTelemetry stats handling for the server.

func WithTelemetryFilter added in v1.0.55

func WithTelemetryFilter(filter TelemetryFilter) ServerOption

WithTelemetryFilter configures a filter to determine which RPCs emit telemetry.

type SpiffeProvider

type SpiffeProvider struct {
	// contains filtered or unexported fields
}

SpiffeProvider implements SecurityProvider using SPIFFE workload API.

func NewSpiffeProvider

func NewSpiffeProvider(ctx context.Context, config *models.SecurityConfig, log logger.Logger) (*SpiffeProvider, error)

func (*SpiffeProvider) Close

func (p *SpiffeProvider) Close() error

func (*SpiffeProvider) GetClientCredentials

func (p *SpiffeProvider) GetClientCredentials(_ context.Context) (grpc.DialOption, error)

func (*SpiffeProvider) GetServerCredentials

func (p *SpiffeProvider) GetServerCredentials(_ context.Context) (grpc.ServerOption, error)

type TelemetryFilter added in v1.0.55

type TelemetryFilter func(*grpcstats.RPCTagInfo) bool

TelemetryFilter allows callers to suppress traces for matching RPCs.

Jump to

Keyboard shortcuts

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