/
system_config.go
61 lines (43 loc) · 1.18 KB
/
system_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package store
import (
"context"
"gorm.io/gorm/clause"
)
type SystemConfig struct {
ConfigKey string `gorm:"primaryKey"`
ConfigValue string
}
func (db *Database) Save(ctx context.Context, configKey string, configValue string) error {
var systemConfig SystemConfig = SystemConfig{
ConfigKey: configKey,
ConfigValue: configValue,
}
update := db.Client.WithContext(ctx).Clauses(clause.OnConflict{
UpdateAll: true,
}).Create(&systemConfig)
return update.Error
}
func (db *Database) GetConfigValue(ctx context.Context, configKey string) string {
var cfgs []SystemConfig
db.Client.WithContext(ctx).Where("configKey = ?", configKey).Find(&cfgs)
if len(cfgs) < 1 {
return ""
}
return cfgs[0].ConfigValue
}
func (db *Database) GetSevenTvToken(ctx context.Context) string {
var cfgs []SystemConfig
db.Client.WithContext(ctx).Where("config_key = ?", "SEVEN_TV_TOKEN").Find(&cfgs)
if len(cfgs) < 1 {
return ""
}
return cfgs[0].ConfigValue
}
func (db *Database) GetBttvToken(ctx context.Context) string {
var cfgs []SystemConfig
db.Client.WithContext(ctx).Where("config_key = ?", "BTTV_TOKEN").Find(&cfgs)
if len(cfgs) < 1 {
return ""
}
return cfgs[0].ConfigValue
}