Files
common/config/welcome.go

41 lines
857 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package config
import (
"context"
"sync"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/glog"
)
var (
welcomeCache map[string]string
welcomeMu sync.RWMutex
welcomeOnce sync.Once
)
// initWelcomeMessages 初始化欢迎话术配置
func initWelcomeMessages(ctx context.Context) {
welcomeOnce.Do(func() {
// 从默认配置文件config.yml读取 welcomes 配置
welcomeMap := g.Cfg().MustGet(ctx, "welcomes").MapStrStr()
welcomeMu.Lock()
welcomeCache = welcomeMap
welcomeMu.Unlock()
glog.Infof(ctx, "已加载欢迎话术配置: %d个方向", len(welcomeMap))
})
}
// GetWelcomeMessage 根据方向名称获取欢迎话术
func GetWelcomeMessage(direction string) string {
ctx := context.Background()
initWelcomeMessages(ctx)
welcomeMu.RLock()
defer welcomeMu.RUnlock()
return welcomeCache[direction]
}