config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLogLevel = LogLevelInfo

Variables

This section is empty.

Functions

This section is empty.

Types

type Loader

type Loader interface {
	// Load loads configuration from all sources and validates it
	// Returns a Provider interface for accessing the configuration
	// If loading fails, returns an error with appropriate context
	Load(ctx context.Context, opts ...Option) (Provider, error)

	// Validate checks if the current configuration is valid
	// Returns nil if valid, error with validation details otherwise
	Validate() error
}

Loader handles the loading and validation of configuration from various sources (files, environment variables, flags)

func NewLoader

func NewLoader(log logger.Logger) Loader

NewLoader creates a new configuration loader

type LogLevel

type LogLevel string

LogLevel represents valid logging levels

const (
	LogLevelDebug   LogLevel = "debug"
	LogLevelInfo    LogLevel = "info"
	LogLevelWarning LogLevel = "warning"
	LogLevelError   LogLevel = "error"
)

func (LogLevel) IsValid

func (l LogLevel) IsValid() bool

IsValid returns whether the log level is valid

func (LogLevel) String

func (l LogLevel) String() string

String implements the Stringer interface

type Option

type Option func(*options) error

Option defines a configuration option that can be passed to Load

func WithConfigFile

func WithConfigFile(path string) Option

WithConfigFile specifies an explicit configuration file path

func WithEnvPrefix

func WithEnvPrefix(prefix string) Option

WithEnvPrefix specifies a custom environment variable prefix Default is "NVIDIACTL"

type Provider

type Provider interface {
	// GetInterval returns the update interval in seconds
	GetInterval() int

	// GetTemperature returns the maximum allowed temperature in Celsius
	GetTemperature() int

	// GetFanSpeed returns the maximum allowed fan speed percentage
	GetFanSpeed() int

	// GetHysteresis returns the required temperature change before adjusting fan speed
	GetHysteresis() int

	// IsPerformanceMode returns whether performance mode is enabled
	IsPerformanceMode() bool

	// IsMonitorMode returns whether monitor-only mode is enabled
	IsMonitorMode() bool

	// GetLogLevel returns the configured logging level
	GetLogLevel() string

	// IsMetricsEnabled returns whether metrics collection is enabled
	IsMetricsEnabled() bool

	// GetMetricsDBPath returns the path to the metrics database
	GetMetricsDBPath() string
}

Provider defines the interface for accessing configuration values All configuration values are immutable after initial loading unless Watch functionality is implemented

type Status

type Status struct {
	// Valid indicates whether the current configuration is valid
	Valid bool
	// ValidationErrors contains any validation errors if Valid is false
	ValidationErrors []ValidationError
}

Status represents the current state of the configuration

func GetStatus

func GetStatus() Status

GetStatus returns the current configuration status

type ValidationError

type ValidationError interface {
	error
	// Field returns the name of the invalid field
	Field() string
	// Value returns the invalid value
	Value() interface{}
	// Reason returns why the value is invalid
	Reason() string
}

ValidationError represents a configuration validation error

type Watcher

type Watcher interface {
	// Watch starts watching for configuration changes
	// The callback is called when configuration changes are detected
	Watch(ctx context.Context, callback func(Provider)) error
}

Watcher enables live configuration updates

Jump to

Keyboard shortcuts

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