39 lines
834 B
Go
39 lines
834 B
Go
package config
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
TelegramBotToken string
|
|
PostgresConnString string
|
|
DeepSeekAPIKey string
|
|
BraveAPIKey string
|
|
}
|
|
|
|
func Load() (*Config, error) {
|
|
cfg := &Config{
|
|
TelegramBotToken: os.Getenv("TELEGRAM_BOT_TOKEN"),
|
|
DeepSeekAPIKey: os.Getenv("DEEPSEEK_API_KEY"),
|
|
BraveAPIKey: os.Getenv("BRAVE_API_KEY"),
|
|
PostgresConnString: getEnv("POSTGRES_CONN_STRING", "postgres://user:password@localhost:5432/db?sslmode=disable"),
|
|
}
|
|
|
|
if cfg.TelegramBotToken == "" {
|
|
return nil, errors.New("TELEGRAM_BOT_TOKEN is required")
|
|
}
|
|
if cfg.BraveAPIKey == "" {
|
|
return nil, errors.New("BRAVE_API_KEY is required")
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|
|
|
|
func getEnv(key, defaultValue string) string {
|
|
if value := os.Getenv(key); value != "" {
|
|
return value
|
|
}
|
|
return defaultValue
|
|
}
|