Add environment config loading and logging setup
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
DiscordToken string
|
||||
LavalinkNodeName string
|
||||
LavalinkAddress string
|
||||
LavalinkPassword string
|
||||
LavalinkSecure bool
|
||||
Debug bool
|
||||
}
|
||||
|
||||
func Load() (Config, error) {
|
||||
token := os.Getenv("DISCORD_TOKEN")
|
||||
if token == "" {
|
||||
return Config{}, errors.New("DISCORD_TOKEN environment variable is required")
|
||||
}
|
||||
|
||||
address := os.Getenv("LAVALINK_ADDRESS")
|
||||
if address == "" {
|
||||
return Config{}, errors.New("LAVALINK_ADDRESS environment variable is required")
|
||||
}
|
||||
|
||||
password := os.Getenv("LAVALINK_PASSWORD")
|
||||
if password == "" {
|
||||
return Config{}, errors.New("LAVALINK_PASSWORD environment variable is required")
|
||||
}
|
||||
|
||||
cfg := Config{
|
||||
DiscordToken: token,
|
||||
LavalinkNodeName: envOrDefault("LAVALINK_NODE_NAME", "main"),
|
||||
LavalinkAddress: address,
|
||||
LavalinkPassword: password,
|
||||
LavalinkSecure: os.Getenv("LAVALINK_SECURE") == "true",
|
||||
Debug: os.Getenv("DEBUG") == "true",
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func envOrDefault(key, fallback string) string {
|
||||
if value := os.Getenv(key); value != "" {
|
||||
return value
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
Reference in New Issue
Block a user