package config import ( "fmt" "os" "github.com/BurntSushi/toml" ) type Config struct { Server ServerConfig `toml:"server"` Database DatabaseConfig `toml:"database"` Yandex YandexConfig `toml:"yandex"` Telegram TelegramConfig `toml:"telegram"` } type ServerConfig struct { Port int `toml:"port"` ShutdownTimeout int `toml:"shutdown_timeout"` ForceShutdownTimeout int `toml:"force_shutdown_timeout"` UsersWhiteList []string `toml:"users_while_list"` } type DatabaseConfig struct { Path string `toml:"path"` } type YandexConfig struct { FolderID string `toml:"folder_id"` SpeechKitAPIKey string `toml:"speech_kit_api_key"` ObjStorageAccessKey string `toml:"object_storage_access_key_id"` ObjStorageSecretKey string `toml:"object_storage_secret_access_key"` ObjStorageBucketName string `toml:"object_storage_bucket_name"` ObjStorageRegion string `toml:"object_storage_region"` ObjStorageEndpoint string `toml:"object_storage_endpoint"` } type TelegramConfig struct { BotToken string `toml:"bot_token"` UpdateTimeout int `toml:"update_timeout"` } // DefaultConfig returns a Config with default values func DefaultConfig() *Config { return &Config{ Server: ServerConfig{ Port: 8080, ShutdownTimeout: 5, ForceShutdownTimeout: 20, }, Database: DatabaseConfig{ Path: "data/transcriber.db", }, Yandex: YandexConfig{ FolderID: "", SpeechKitAPIKey: "", ObjStorageAccessKey: "", ObjStorageSecretKey: "", ObjStorageBucketName: "", ObjStorageRegion: "ru-central1", ObjStorageEndpoint: "https://storage.yandexcloud.net/", }, Telegram: TelegramConfig{ BotToken: "", UpdateTimeout: 10, }, } } // LoadConfig loads configuration from a TOML file func LoadConfig(path string) (*Config, error) { // Check if file exists if _, err := os.Stat(path); os.IsNotExist(err) { return nil, fmt.Errorf("config file not found: %s", path) } config := DefaultConfig() // Load configuration from file if _, err := toml.DecodeFile(path, &config); err != nil { return nil, fmt.Errorf("failed to decode config file: %w", err) } return config, nil }