config

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config provides application configuration loading and validation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppleTV

type AppleTV struct {
	Entity  string `yaml:"entity"`
	Name    string `yaml:"name"`
	Default bool   `yaml:"default"`
}

AppleTV represents an Apple TV media player

type Config

type Config struct {
	Port          string
	DataDir       string // Directory for all generated files (database, secrets)
	LogLevel      string
	SessionSecret string
	CSRFKey       []byte // 32-byte key for CSRF protection
	EncryptionKey []byte // 32-byte key for AES-256-GCM encryption
	DevMode       bool
	RequireTLS    bool
}

Config holds application-level configuration from environment variables. User data (Plex servers, Home Assistant, Apple TVs) is stored in config.yml and loaded via LoadRuntimeConfig().

func Load

func Load() (*Config, error)

Load reads configuration from environment variables and validates required fields. It attempts to load from a .env file if present, then reads from the environment. Generates and persists a random SESSION_SECRET if not set.

func (*Config) ConfigPath

func (c *Config) ConfigPath() string

ConfigPath returns the full path to the runtime configuration file

func (*Config) DatabasePath

func (c *Config) DatabasePath() string

DatabasePath returns the full path to the database file

func (*Config) LogPath

func (c *Config) LogPath() string

LogPath returns the full path to the log file

type Connection

type Connection struct {
	URI   string `yaml:"uri"`
	Local bool   `yaml:"local"`
}

Connection represents a Plex server connection URL

type HAConfig

type HAConfig struct {
	URL string `yaml:"url"`
}

HAConfig represents Home Assistant configuration

type PlexServer

type PlexServer struct {
	ID          string       `yaml:"id"`
	Name        string       `yaml:"name"`
	Owner       string       `yaml:"owner"`
	Connections []Connection `yaml:"connections"`
}

PlexServer represents a Plex Media Server configuration

type RuntimeConfig

type RuntimeConfig struct {
	Version       int          `yaml:"version"`
	PlexServers   []PlexServer `yaml:"plex_servers"`
	HomeAssistant HAConfig     `yaml:"home_assistant"`
	AppleTVs      []AppleTV    `yaml:"apple_tvs"`
}

RuntimeConfig represents the user-configurable runtime settings

func LoadRuntimeConfig

func LoadRuntimeConfig(path string) (*RuntimeConfig, error)

LoadRuntimeConfig loads configuration from a YAML file

func (*RuntimeConfig) GetAppleTVByEntity

func (c *RuntimeConfig) GetAppleTVByEntity(entity string) *AppleTV

GetAppleTVByEntity finds an Apple TV by its entity ID

func (*RuntimeConfig) GetDefaultAppleTV

func (c *RuntimeConfig) GetDefaultAppleTV() *AppleTV

GetDefaultAppleTV returns the default Apple TV, or the first one if none is marked default

func (*RuntimeConfig) GetPlexServerByID

func (c *RuntimeConfig) GetPlexServerByID(id string) *PlexServer

GetPlexServerByID finds a Plex server by its ID

func (*RuntimeConfig) IsEmpty

func (c *RuntimeConfig) IsEmpty() bool

IsEmpty returns true if the configuration has no servers or HA configured

func (*RuntimeConfig) Save

func (c *RuntimeConfig) Save(path string) error

Save writes the configuration to a YAML file

func (*RuntimeConfig) Validate

func (c *RuntimeConfig) Validate() error

Validate checks if the configuration is valid

Jump to

Keyboard shortcuts

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