refactor: analysis mode.

This commit is contained in:
2026-04-27 16:49:00 +08:00
parent 4bd6486a14
commit 51871c352a
3 changed files with 122 additions and 15 deletions
+36 -12
View File
@@ -12,19 +12,23 @@ import (
var DB *gorm.DB
var App AppConfig
type DBConfig struct {
Host string `mapstructure:"host" yaml:"host"`
Port string `mapstructure:"port" yaml:"port"`
User string `mapstructure:"user" yaml:"user"`
Password string `mapstructure:"password" yaml:"password"`
Name string `mapstructure:"name" yaml:"name"`
}
type AIConfig struct {
BaseURL string `mapstructure:"base_url" yaml:"base_url"`
APIKey string `mapstructure:"api_key" yaml:"api_key"`
Model string `mapstructure:"model" yaml:"model"`
}
type AppConfig struct {
DB struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
Name string `yaml:"name"`
} `yaml:"database"`
AI struct {
BaseURL string `yaml:"base_url"`
APIKey string `yaml:"api_key"`
Model string `yaml:"model"`
} `yaml:"ai"`
DB DBConfig `mapstructure:"database" yaml:"database"`
AI AIConfig `mapstructure:"ai" yaml:"ai"`
}
func InitConfig() {
@@ -40,6 +44,10 @@ func InitConfig() {
}
func ConnectDB() {
if err := validateDBConfig(App.DB); err != nil {
panic("Failed to connect database: " + err.Error())
}
dsn := "host=" + App.DB.Host +
" user=" + App.DB.User +
" password=" + App.DB.Password +
@@ -54,6 +62,22 @@ func ConnectDB() {
}
}
func validateDBConfig(cfg DBConfig) error {
if cfg.Host == "" {
return fmt.Errorf("missing config: database.host")
}
if cfg.Port == "" {
return fmt.Errorf("missing config: database.port")
}
if cfg.User == "" {
return fmt.Errorf("missing config: database.user")
}
if cfg.Name == "" {
return fmt.Errorf("missing config: database.name")
}
return nil
}
func GetAIConfig() (baseURL, apiKey, model string, err error) {
if App.AI.BaseURL == "" {
return "", "", "", fmt.Errorf("missing config: ai.base_url")