Initial commit: web_hghl_server

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 16:28:14 +08:00
co-authored by Claude Opus 4.7
commit 65fca60622
653 changed files with 135901 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
package cfg
import (
"context"
"strings"
"sync"
"go.mongodb.org/mongo-driver/bson"
)
var appKeyCache struct {
sync.RWMutex
value string
ready bool
}
// CacheAppKey 把系统配置里的 appKey 放进内存,供媒资写接口读取。
func CacheAppKey(appKey string) {
appKeyCache.Lock()
appKeyCache.value = strings.TrimSpace(appKey)
appKeyCache.ready = true
appKeyCache.Unlock()
}
// CachedAppKey 返回已缓存的 appKey。缓存未建立时读取 sys_cfg 并写入缓存。
func CachedAppKey(ctx context.Context) string {
appKeyCache.RLock()
if appKeyCache.ready {
value := appKeyCache.value
appKeyCache.RUnlock()
return value
}
appKeyCache.RUnlock()
sysCfg, serr := FindOneSysCfg(ctx, bson.M{FN.SysCfg.Id: 1})
if serr != nil || sysCfg == nil {
return ""
}
value := strings.TrimSpace(sysCfg.AppKey)
CacheAppKey(value)
return value
}