We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c5dfff5 commit 12f8aa5Copy full SHA for 12f8aa5
service/config.go
@@ -1,6 +1,8 @@
1
package service
2
3
import (
4
+ "sync"
5
+
6
"github.com/quarkcloudio/quark-go/v3/dal/db"
7
"github.com/quarkcloudio/quark-go/v3/model"
8
)
@@ -9,6 +11,7 @@ type ConfigService struct{}
9
11
10
12
// 存储配置
13
var webConfig = make(map[string]string)
14
+var mu sync.Mutex
15
16
// 初始化
17
func NewConfigService() *ConfigService {
@@ -19,6 +22,9 @@ func NewConfigService() *ConfigService {
19
22
func (p *ConfigService) Refresh() {
20
23
configs := []model.Config{}
21
24
db.Client.Where("status", 1).Find(&configs)
25
+ // 确保对 webConfig map 的写入操作是互斥的,防止并发写入导致的数据竞争
26
+ mu.Lock()
27
+ defer mu.Unlock()
28
for _, config := range configs {
29
webConfig[config.Name] = config.Value
30
}
0 commit comments