grpcserver

package
v0.0.4 Latest Latest
Warning

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

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

Documentation

Overview

Package grpcserver provides a lakta module for running gRPC servers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Instance name
	Name string `koanf:"-"`

	// Host specifies the address for the GRPC server to bind to.
	Host string `koanf:"host"`

	// Port represents the port number on which the GRPC server listens.
	Port uint16 `koanf:"port"`

	// HealthCheck determines whether gRPC health checking is enabled or disabled.
	HealthCheck bool `koanf:"health_check"`

	// Services is a map of gRPC service descriptors and their implementations to be registered on the server.
	Services map[*grpc.ServiceDesc]any `code_only:"WithService" koanf:"-"`
}

Config represents configuration for GRPC server Module

func NewConfig

func NewConfig(options ...Option) Config

NewConfig returns configuration with provided options based on defaults.

func NewDefaultConfig

func NewDefaultConfig() Config

NewDefaultConfig returns default configuration

func (*Config) AddrPort

func (c *Config) AddrPort() (netip.AddrPort, error)

AddrPort returns the parsed address and port for the server.

func (*Config) LoadFromKoanf

func (c *Config) LoadFromKoanf(k *koanf.Koanf, path string) error

LoadFromKoanf loads configuration from koanf instance at the given path.

type Module

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

Module manages a gRPC server lifecycle.

func NewModule

func NewModule(options ...Option) *Module

NewModule creates a new gRPC server module with the given options.

func (*Module) ConfigPath

func (m *Module) ConfigPath() string

ConfigPath returns the koanf path for this module's configuration.

func (*Module) Init

func (m *Module) Init(ctx context.Context) error

Init loads configuration and creates the gRPC server with interceptors.

func (*Module) LoadConfig

func (m *Module) LoadConfig(k *koanf.Koanf) error

LoadConfig loads configuration from koanf.

func (*Module) Name

func (m *Module) Name() string

Name returns the instance name.

func (*Module) Shutdown

func (m *Module) Shutdown(_ context.Context) error

Shutdown gracefully stops the gRPC server.

func (*Module) Start

func (m *Module) Start(ctx context.Context) error

Start begins listening and serving gRPC requests.

type Option

type Option func(m *Config)

Option configures the Module.

func WithHealthCheck added in v0.0.2

func WithHealthCheck(enabled bool) Option

WithHealthCheck enables or disables the gRPC health check.

func WithHost added in v0.0.2

func WithHost(host string) Option

WithHost sets the host address.

func WithName

func WithName(name string) Option

WithName sets the instance name for this module.

func WithPort added in v0.0.2

func WithPort(port uint16) Option

WithPort sets the port number.

func WithService

func WithService(serviceDescriptor *grpc.ServiceDesc, service any) Option

WithService adds service to the list of services to be registered (code-only).

Jump to

Keyboard shortcuts

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