3 Commits

Author SHA1 Message Date
6980b31da7 修复consul限流gateway问题 2026-04-29 10:04:30 +08:00
lmk
4960021748 gse配置修改 2026-04-28 14:15:31 +08:00
qhd
960dca6a50 fix: 修正 creator 字段空值检查逻辑 2026-04-22 15:03:39 +08:00
3 changed files with 45 additions and 3 deletions

View File

@@ -251,7 +251,7 @@ func GetInstanceAddr(ctx context.Context, name string) (addr string, err error)
err = errors.New("获取服务监听器失败")
return
}
defer watch.Close()
service, err := watch.Proceed()
if err != nil || service == nil {
err = errors.New("获取服务实例失败")

View File

@@ -188,7 +188,7 @@ func insertHook(ctx context.Context, in *gdb.HookInsertInput) (result sql.Result
}
}
if _, ok := in.Data[i]["creator"]; ok {
if g.IsEmpty(in.Data[i]["tenant_id"]) {
if g.IsEmpty(in.Data[i]["creator"]) {
if !g.IsEmpty(userInfo.UserName) {
in.Data[i]["creator"] = userInfo.UserName
} else {

View File

@@ -2,6 +2,8 @@ package utils
import (
"context"
"os"
"path/filepath"
"sort"
"sync"
@@ -54,7 +56,24 @@ func newGseTool() (tool *gseTool, err error) {
// 2. 初始化 TF-IDF 提取器
tfidf := &extracker.TagExtracter{}
tfidf.WithGse(seg)
err = tfidf.LoadIdf()
// 尝试从默认路径加载 IDF 字典
idfPath := getIdfDictPath()
if idfPath != "" {
// 如果找到自定义路径,使用 LoadDict 方法加载
err = tfidf.LoadDict(idfPath)
if err != nil {
glog.Warningf(context.Background(), "加载自定义 IDF 字典失败 [%s]: %v将使用默认字典", idfPath, err)
// 回退到默认加载方式
err = tfidf.LoadIdf()
} else {
glog.Infof(context.Background(), "成功加载自定义 IDF 字典: %s", idfPath)
}
} else {
// 使用默认的 IDF 字典
err = tfidf.LoadIdf()
}
if err != nil {
return
}
@@ -71,6 +90,29 @@ func newGseTool() (tool *gseTool, err error) {
return
}
// getIdfDictPath 获取 IDF 字典文件路径
func getIdfDictPath() string {
// 1. 尝试从容器内的默认挂载路径加载Docker 卷映射)
containerPath := "/app/dict/zh/idf.txt"
if _, err := os.Stat(containerPath); err == nil {
return containerPath
}
// 2. 尝试从当前工作目录的 dict/zh/idf.txt 加载
workDir, err := os.Getwd()
if err != nil {
return ""
}
localPath := filepath.Join(workDir, "dict", "zh", "idf.txt")
if _, err := os.Stat(localPath); err == nil {
return localPath
}
// 3. 如果没有找到自定义路径,返回空字符串,使用默认字典
return ""
}
// Cut 分词(关键词提取唯一正确模式:精确模式 + HMM
func (k *gseTool) Cut(text string) []string {
return k.seg.Cut(text, true)