This commit is contained in:
parent
9c78ea2d48
commit
7c684af8c3
79 changed files with 3594 additions and 3257 deletions
59
internal/config/config.go
Normal file
59
internal/config/config.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Config holds all application configuration
|
||||
type Config struct {
|
||||
Debug bool
|
||||
Hostname string
|
||||
Port string
|
||||
LogLevel string
|
||||
SecretKey string
|
||||
DatabasePath string
|
||||
SlackConfig SlackConfig
|
||||
TelegramConfig TelegramConfig
|
||||
}
|
||||
|
||||
// SlackConfig holds Slack platform configuration
|
||||
type SlackConfig struct {
|
||||
Token string
|
||||
BotOAuthAccessToken string
|
||||
}
|
||||
|
||||
// TelegramConfig holds Telegram platform configuration
|
||||
type TelegramConfig struct {
|
||||
Token string
|
||||
}
|
||||
|
||||
// Load loads configuration from environment variables
|
||||
func Load() (*Config, error) {
|
||||
config := &Config{
|
||||
Debug: getEnv("DEBUG", "n") == "y",
|
||||
Hostname: getEnv("BUTTERROBOT_HOSTNAME", "butterrobot-dev.int.fmartingr.network"),
|
||||
Port: getEnv("PORT", "8080"),
|
||||
LogLevel: getEnv("LOG_LEVEL", "ERROR"),
|
||||
SecretKey: getEnv("SECRET_KEY", "1234"),
|
||||
DatabasePath: getEnv("DATABASE_PATH", "butterrobot.db"),
|
||||
SlackConfig: SlackConfig{
|
||||
Token: getEnv("SLACK_TOKEN", ""),
|
||||
BotOAuthAccessToken: getEnv("SLACK_BOT_OAUTH_ACCESS_TOKEN", ""),
|
||||
},
|
||||
TelegramConfig: TelegramConfig{
|
||||
Token: getEnv("TELEGRAM_TOKEN", ""),
|
||||
},
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// getEnv retrieves an environment variable value or returns a default value
|
||||
func getEnv(key, defaultValue string) string {
|
||||
value := os.Getenv(key)
|
||||
if strings.TrimSpace(value) == "" {
|
||||
return defaultValue
|
||||
}
|
||||
return value
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue