daemon

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package daemon provides the core daemon bootstrapping and lifecycle management.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingLogger is returned when logger is not provided
	ErrMissingLogger = errors.New("logger is required")

	// ErrMissingAPIHandler is returned when API handler is not provided
	ErrMissingAPIHandler = errors.New("API handler is required")

	// ErrManagerNotStarted is returned when trying to shutdown a manager that hasn't started
	ErrManagerNotStarted = errors.New("manager not started")

	// ErrServerStartFailed is returned when a server fails to start
	ErrServerStartFailed = errors.New("server failed to start")
)

Functions

func WaitForShutdown

func WaitForShutdown() context.Context

WaitForShutdown waits for interrupt/termination signals.

Types

type Config

type Config struct {
	// Version is the build version
	Version string

	// ConfigPath is the path to the YAML config file
	ConfigPath string

	// ListenAddr is the HTTP server listen address
	ListenAddr string

	// Server timeouts
	ReadTimeout    time.Duration
	WriteTimeout   time.Duration
	IdleTimeout    time.Duration
	MaxHeaderBytes int

	// ShutdownTimeout is the graceful shutdown timeout
	ShutdownTimeout time.Duration
}

Config holds daemon configuration.

type Daemon

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

Daemon represents the xg2g daemon instance.

func New

func New(cfg Config) (*Daemon, error)

New creates a new daemon instance.

func (*Daemon) Shutdown

func (d *Daemon) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the daemon.

func (*Daemon) Start

func (d *Daemon) Start(ctx context.Context, handler http.Handler) error

Start starts the daemon and all its components.

type Deps added in v1.6.0

type Deps struct {
	// Logger is the structured logger for the daemon
	Logger zerolog.Logger

	// Config is the jobs configuration (OpenWebIF, EPG, etc.)
	Config jobs.Config

	// APIHandler is the HTTP handler for the API server
	APIHandler http.Handler

	// ProxyConfig contains proxy server configuration (if enabled)
	ProxyConfig *ProxyConfig

	// MetricsHandler is the HTTP handler for Prometheus metrics (if enabled)
	MetricsHandler http.Handler
}

Deps contains dependencies required by the daemon Manager. This allows for clean dependency injection and easier testing.

func (*Deps) Validate added in v1.6.0

func (d *Deps) Validate() error

Validate checks if the dependencies are valid.

type Manager added in v1.6.0

type Manager interface {
	// Start starts all configured servers and blocks until shutdown
	Start(ctx context.Context) error

	// Shutdown gracefully shuts down all servers
	Shutdown(ctx context.Context) error

	// RegisterShutdownHook registers a function to be called during shutdown
	RegisterShutdownHook(name string, hook ShutdownHook)
}

Manager manages the daemon lifecycle: starting servers, handling shutdown.

func NewManager added in v1.6.0

func NewManager(serverCfg config.ServerConfig, deps Deps) (Manager, error)

NewManager creates a new daemon manager with the given configuration and dependencies.

type ProxyConfig added in v1.6.0

type ProxyConfig struct {
	// ListenAddr is the proxy listen address (e.g., ":18000")
	ListenAddr string

	// TargetURL is the upstream target URL (optional if StreamDetector is provided)
	TargetURL string

	// ReceiverHost is the receiver hostname/IP for Smart Detection fallback
	ReceiverHost string

	// StreamDetector enables smart port detection (8001 vs 17999)
	StreamDetector *openwebif.StreamDetector

	// Logger is the logger for the proxy
	Logger zerolog.Logger
}

ProxyConfig holds proxy server configuration.

type ShutdownHook added in v1.7.0

type ShutdownHook func(ctx context.Context) error

ShutdownHook is a function that performs cleanup during graceful shutdown. Hooks are executed in reverse registration order (LIFO).

Jump to

Keyboard shortcuts

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