refactor: 重构配置管理,使用强类型配置结构并更新相关代码
This commit is contained in:
@@ -8,6 +8,18 @@ import (
|
||||
|
||||
var ConfigManager = &configManager{}
|
||||
|
||||
type Config struct {
|
||||
Admin int64 `yaml:"admin"`
|
||||
SteamApiKey string `yaml:"steam_api_key"`
|
||||
ProxyAddr string `yaml:"proxy_addr"`
|
||||
NapcatWsSrv string `yaml:"napcat_ws_srv"`
|
||||
NapcatHttpSrv string `yaml:"napcat_http_srv"`
|
||||
OpenaiApiKey string `yaml:"openai_api_key"`
|
||||
OpenaiApiBaseUrl string `yaml:"openai_api_base_url"`
|
||||
OpenaiModelName string `yaml:"openai_model_name"`
|
||||
OpenaiPrompt string `yaml:"openai_prompt"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
err := ConfigManager.LoadConfig("config.yml")
|
||||
if err != nil {
|
||||
@@ -16,7 +28,8 @@ func init() {
|
||||
}
|
||||
|
||||
type configManager struct {
|
||||
propertys map[string]string
|
||||
// propertys map[string]string
|
||||
config *Config
|
||||
}
|
||||
|
||||
func (cm *configManager) LoadConfig(path string) error {
|
||||
@@ -25,13 +38,13 @@ func (cm *configManager) LoadConfig(path string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = yaml.Unmarshal(data, &cm.propertys)
|
||||
err = yaml.Unmarshal(data, &cm.config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cm *configManager) GetProperty(key string) string {
|
||||
return cm.propertys[key]
|
||||
func (cm *configManager) GetConfig() *Config {
|
||||
return cm.config
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user