init: initial commit

This commit is contained in:
Blizzard
2026-04-01 14:09:33 +08:00
commit aef2e152dc
66 changed files with 6540 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
package config
import (
"fmt"
"github.com/spf13/viper"
)
type DatabaseConfig struct {
DSN string `mapstructure:"dsn"`
}
type DeepSeekConfig struct {
APIKey string `mapstructure:"api_key"`
Model string `mapstructure:"model"`
TimeoutSeconds int `mapstructure:"timeout_seconds"`
MaxTokens int `mapstructure:"max_tokens"`
}
type AppConfig struct {
Database DatabaseConfig `mapstructure:"database"`
DeepSeek DeepSeekConfig `mapstructure:"deepseek"`
}
var Global AppConfig
func Load() error {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("$HOME/.ai-expert-sidebar")
// Defaults
viper.SetDefault("database.dsn",
"root:password@tcp(127.0.0.1:3306)/ai_expert?charset=utf8mb4&parseTime=True&loc=Local")
viper.SetDefault("deepseek.api_key", "")
viper.SetDefault("deepseek.model", "deepseek-chat")
viper.SetDefault("deepseek.timeout_seconds", 60)
viper.SetDefault("deepseek.max_tokens", 1024)
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
return fmt.Errorf("config read error: %w", err)
}
}
return viper.Unmarshal(&Global)
}