Files
FernandoJVideira 26e1d9b094 feat: update Docker configuration and environment handling
- Added PostgreSQL service to docker-compose.yml with health checks and persistent storage.
- Updated bot service to use environment variable substitution for database connection string.
- Upgraded Go version in Dockerfile to 1.26.1-alpine.
- Modified config loading to ignore missing .env file for better compatibility with Docker.
2026-03-18 14:08:21 +00:00

59 lines
1.2 KiB
Go

package config
import (
"fmt"
"os"
"github.com/joho/godotenv"
)
type Config struct {
BotToken string
AppID string
GuildID string
DBHost string
LavalinkHost string
LavalinkPass string
TwitchClientID string
}
func LoadConfig() (*Config, error) {
// Load .env if present (e.g. local dev). Ignore if missing (e.g. Docker injects env vars).
_ = godotenv.Load()
token := os.Getenv("BOT_TOKEN")
if token == "" {
return nil, fmt.Errorf("BOT_TOKEN is not set")
}
appID := os.Getenv("APP_ID")
if appID == "" {
return nil, fmt.Errorf("APP_ID is not set")
}
guildID := os.Getenv("GUILD_ID")
dbHost := os.Getenv("DB_HOST")
if dbHost == "" {
return nil, fmt.Errorf("DB_HOST is not set")
}
lavalinkHost := os.Getenv("LAVALINK_HOST")
lavalinkPass := os.Getenv("LAVALINK_PASSWORD")
twitchClientID := os.Getenv("TWITCH_CLIENT_ID")
if twitchClientID == "" {
return nil, fmt.Errorf("TWITCH_CLIENT_ID is not set")
}
return &Config{
BotToken: token,
AppID: appID,
GuildID: guildID,
DBHost: dbHost,
LavalinkHost: lavalinkHost,
LavalinkPass: lavalinkPass,
TwitchClientID: twitchClientID,
}, nil
}