feat: initial commit
This commit is contained in:
69
internal/config/config.go
Normal file
69
internal/config/config.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Bot BotConfig
|
||||
N8n N8nConfig
|
||||
Speech SpeechConfig
|
||||
Redis RedisConfig
|
||||
Server ServerConfig
|
||||
Log LogConfig
|
||||
}
|
||||
|
||||
type BotConfig struct {
|
||||
Token string `envconfig:"TELEGRAM_BOT_TOKEN" required:"true"`
|
||||
Mode string `envconfig:"BOT_MODE" default:"polling"`
|
||||
WebhookURL string `envconfig:"TELEGRAM_WEBHOOK_URL"`
|
||||
Debug bool `envconfig:"TELEGRAM_DEBUG" default:"false"`
|
||||
}
|
||||
|
||||
type N8nConfig struct {
|
||||
BaseURL string `envconfig:"N8N_BASE_URL" required:"true"`
|
||||
AuthToken string `envconfig:"N8N_AUTH_TOKEN"`
|
||||
TimeoutSecs int `envconfig:"N8N_TIMEOUT" default:"30"`
|
||||
RetryCount int `envconfig:"N8N_RETRY_COUNT" default:"3"`
|
||||
}
|
||||
|
||||
type SpeechConfig struct {
|
||||
Provider string `envconfig:"STT_PROVIDER" default:"openai"`
|
||||
OpenAIKey string `envconfig:"OPENAI_API_KEY"`
|
||||
WhisperModel string `envconfig:"WHISPER_MODEL" default:"whisper-1"`
|
||||
Language string `envconfig:"WHISPER_LANGUAGE" default:""`
|
||||
FFmpegPath string `envconfig:"FFMPEG_PATH" default:"ffmpeg"`
|
||||
}
|
||||
|
||||
type RedisConfig struct {
|
||||
URL string `envconfig:"REDIS_URL" default:"redis://localhost:6379"`
|
||||
TTLHours int `envconfig:"SESSION_TTL" default:"24"`
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
Port int `envconfig:"SERVER_PORT" default:"8080"`
|
||||
}
|
||||
|
||||
type LogConfig struct {
|
||||
Level string `envconfig:"LOG_LEVEL" default:"info"`
|
||||
Format string `envconfig:"LOG_FORMAT" default:"json"`
|
||||
}
|
||||
|
||||
func Load() (*Config, error) {
|
||||
var cfg Config
|
||||
if err := envconfig.Process("", &cfg); err != nil {
|
||||
return nil, fmt.Errorf("load config: %w", err)
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
func MustLoad() *Config {
|
||||
cfg, err := Load()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "fatal: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
Reference in New Issue
Block a user