| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package config
- import (
- "fmt"
- "github.com/spf13/viper"
- )
- type Config struct {
- Server ServerConfig
- MySQL MySQLConfig
- Redis RedisConfig
- Telegram TelegramConfig
- LLM LLMConfig
- Serper SerperConfig
- GitHub GitHubConfig
- }
- type ServerConfig struct {
- Port int
- }
- type MySQLConfig struct {
- Host string
- Port int
- User string
- Password string
- Database string
- }
- type RedisConfig struct {
- Host string
- Port int
- Password string
- DB int
- }
- type TelegramConfig struct {
- AppID int `mapstructure:"app_id"`
- AppHash string `mapstructure:"app_hash"`
- Accounts []TGAccount
- }
- type TGAccount struct {
- Phone string
- SessionFile string `mapstructure:"session_file"`
- }
- type LLMConfig struct {
- Provider string
- BaseURL string `mapstructure:"base_url"`
- APIKey string `mapstructure:"api_key"`
- Model string
- Timeout string
- }
- type SerperConfig struct {
- APIKey string `mapstructure:"api_key"`
- ResultsPerPage int `mapstructure:"results_per_page"`
- MaxPages int `mapstructure:"max_pages"`
- }
- type GitHubConfig struct {
- Token string
- }
- var global *Config
- func Load(path string) (*Config, error) {
- v := viper.New()
- v.SetConfigFile(path)
- v.SetConfigType("yaml")
- if err := v.ReadInConfig(); err != nil {
- return nil, fmt.Errorf("read config file: %w", err)
- }
- cfg := &Config{}
- if err := v.Unmarshal(cfg); err != nil {
- return nil, fmt.Errorf("unmarshal config: %w", err)
- }
- global = cfg
- return cfg, nil
- }
- func Get() *Config {
- return global
- }
|