Nik Afiq 5d732405b8
Some checks failed
CI / test (push) Successful in 34s
CI / build-ai-gateway (push) Successful in 2m34s
CI / build-ha-gateway (push) Failing after 23s
CI / build-discord-bot (push) Failing after 25s
feat: integrate AI gateway for free-form queries in discord-bot
2026-04-21 21:52:41 +09:00

51 lines
1.2 KiB
Go

package config
import (
"errors"
"os"
)
// Config holds runtime configuration for the Discord bot process.
type Config struct {
DiscordToken string
GuildID string
HAGatewayAddr string
AIGatewayAddr string
TLSDir string
OTELEndpoint string
LogLevel string
LogFormat string
}
// Load reads Discord bot configuration from environment variables.
func Load() (*Config, error) {
token := os.Getenv("DISCORD_TOKEN")
if token == "" {
return nil, errors.New("DISCORD_TOKEN is required but not set")
}
addr := os.Getenv("HA_GATEWAY_ADDR")
if addr == "" {
return nil, errors.New("HA_GATEWAY_ADDR is required but not set")
}
return &Config{
DiscordToken: token,
GuildID: os.Getenv("GUILD_ID"),
HAGatewayAddr: addr,
AIGatewayAddr: getenvDefault("AI_GATEWAY_ADDR", "ai-gateway.home-services.svc.cluster.local:50052"),
TLSDir: os.Getenv("TLS_DIR"),
OTELEndpoint: os.Getenv("OTEL_ENDPOINT"),
LogLevel: getenvDefault("LOG_LEVEL", "info"),
LogFormat: getenvDefault("LOG_FORMAT", "json"),
}, nil
}
// getenvDefault keeps config loading concise for optional variables with defaults.
func getenvDefault(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}