kefu/models/configs.go

43 lines
883 B
Go

package models
var CustomConfigs map[string]string
type Config struct {
ID uint `gorm:"primary_key" json:"id"`
ConfName string `json:"conf_name"`
ConfKey string `json:"conf_key"`
ConfValue string `json:"conf_value"`
}
func UpdateConfig(key string, value string) {
c := map[string]string{
"conf_value": value,
}
DB.Model(&Config{}).Where("conf_key = ?", key).Update(c)
InitConfig()
}
func FindConfigs() []Config {
var config []Config
DB.Find(&config)
return config
}
func InitConfig() {
CustomConfigs = make(map[string]string)
list := FindConfigs()
for _, item := range list {
CustomConfigs[item.ConfKey] = item.ConfValue
}
}
func FindConfig(key string) string {
value, ok := CustomConfigs[key]
if !ok {
return ""
}
//for _, config := range CustomConfigs {
// if key == config.ConfKey {
// return config.ConfValue
// }
//}
return value
}