feat: added web server with currently playing song

This commit is contained in:
Felipe M 2025-05-13 12:27:01 +02:00
parent 1a4986f294
commit 7f16452a99
Signed by: fmartingr
GPG key ID: CCFBC5637D4000A8
12 changed files with 847 additions and 9 deletions

View file

@ -32,6 +32,10 @@ type Config struct {
// Jukebox configuration
AudioVolume float64
TimeoutSec int
// Web server configuration
WebEnabled bool
WebAddr string
}
// Load loads the configuration from environment variables and .env file
@ -67,6 +71,10 @@ func Load() (*Config, error) {
// Jukebox
AudioVolume: getEnvFloat(envPrefix+"AUDIO_VOLUME", 0.5),
TimeoutSec: getEnvInt(envPrefix+"TIMEOUT_SEC", 30),
// Web server
WebEnabled: getEnvBool(envPrefix+"WEB_ENABLED", true),
WebAddr: getEnv(envPrefix+"WEB_ADDR", ":8080"),
}
if err := config.validate(); err != nil {
@ -137,6 +145,18 @@ func getEnvFloat(key string, defaultValue float64) float64 {
return defaultValue
}
// getEnvBool gets an environment variable as a boolean or returns a default value
func getEnvBool(key string, defaultValue bool) bool {
if value, exists := os.LookupEnv(key); exists {
if strings.ToLower(value) == "true" || value == "1" {
return true
} else if strings.ToLower(value) == "false" || value == "0" {
return false
}
}
return defaultValue
}
// PrintDebugInfo prints helpful debugging information for environment variables
func PrintDebugInfo() {
slog.Info("=== Configuration Debug Information ===")
@ -152,6 +172,8 @@ func PrintDebugInfo() {
checkEnvVar(envPrefix + "SUBSONIC_VERSION")
checkEnvVar(envPrefix + "AUDIO_VOLUME")
checkEnvVar(envPrefix + "TIMEOUT_SEC")
checkEnvVar(envPrefix + "WEB_ENABLED")
checkEnvVar(envPrefix + "WEB_ADDR")
slog.Info("Troubleshooting tips:")
slog.Info("1. Your .env file is in the correct directory")