package config import ( "github.com/disgoorg/snowflake/v2" log "github.com/sirupsen/logrus" "os" "strconv" ) type Config struct { AppConf AppConfig TgConf TelegramConfig DsConf DiscordConfig } type AppConfig struct { LogLvl string } type TelegramConfig struct { Token string ChatID int64 } type DiscordConfig struct { Token string GuildID snowflake.ID ChannelID snowflake.ID } func NewConfig() *Config { return &Config{ AppConfig{ LogLvl: getEnv("APP_LOG_LEVEL", "info"), }, TelegramConfig{ Token: getEnv("TELEGRAM_TOKEN", ""), ChatID: convertChatID(getEnv("TELEGRAM_CHANNEL_ID", "")), }, DiscordConfig{ Token: getEnv("DISCORD_TOKEN", ""), GuildID: convertID(getEnv("GUILD_ID", "")), ChannelID: convertID(getEnv("CHANNEL_ID", "")), }, } } func getEnv(key, fallback string) string { if value, ok := os.LookupEnv(key); ok { return value } return fallback } func convertID(channelIDStr string) snowflake.ID { channelIDUint, err := strconv.ParseUint(channelIDStr, 10, 64) if err != nil { log.Fatal("Cannot convert channel ID to snowflake ID") } return snowflake.ID(channelIDUint) } func convertChatID(str string) int64 { id, err := strconv.ParseInt(str, 10, 64) if err != nil { log.Fatal("Cannot convert string to int64") } return id }