Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6980b31da7 | |||
| 4960021748 | |||
| 960dca6a50 | |||
| 518d45d296 |
@@ -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("获取服务实例失败")
|
||||
|
||||
@@ -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 {
|
||||
|
||||
45
http/http.go
45
http/http.go
@@ -2,6 +2,7 @@ package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
@@ -129,28 +130,28 @@ func doRequest(ctx context.Context, method string, url string, headers map[strin
|
||||
return
|
||||
}
|
||||
defer response.Close()
|
||||
//result := response.ReadAll()
|
||||
//
|
||||
//// 统一处理内部API响应格式:{code:200,message:"",data:{...}}
|
||||
//resultStrut := &ghttp.DefaultHandlerResponse{}
|
||||
//
|
||||
//if err = gconv.Struct(result, &resultStrut); err != nil { // 修复:增加err检查
|
||||
// return errors.New("响应解析失败: " + err.Error())
|
||||
//}
|
||||
//
|
||||
//// 添加调试日志:打印解析后的结构
|
||||
//g.Log().Debugf(ctx, "[HTTP] 解析后结构: Code=%d, Message=%s, Data类型=%T, Data值=%+v",
|
||||
// resultStrut.Code, resultStrut.Message, resultStrut.Data, resultStrut.Data)
|
||||
//
|
||||
//if resultStrut.Code == 200 || resultStrut.Code == 0 {
|
||||
// if err = gconv.Struct(resultStrut.Data, target); err != nil { // 修复:增加err检查
|
||||
// return errors.New("数据解析失败: " + err.Error())
|
||||
// }
|
||||
// // 添加调试日志:打印最终的target
|
||||
// g.Log().Debugf(ctx, "[HTTP] 最终target: %+v", target)
|
||||
//} else {
|
||||
// err = errors.New(resultStrut.Message)
|
||||
//}
|
||||
result := response.ReadAll()
|
||||
|
||||
// 统一处理内部API响应格式:{code:200,message:"",data:{...}}
|
||||
resultStrut := &ghttp.DefaultHandlerResponse{}
|
||||
|
||||
if err = gconv.Struct(result, &resultStrut); err != nil { // 修复:增加err检查
|
||||
return errors.New("响应解析失败: " + err.Error())
|
||||
}
|
||||
|
||||
// 添加调试日志:打印解析后的结构
|
||||
g.Log().Debugf(ctx, "[HTTP] 解析后结构: Code=%d, Message=%s, Data类型=%T, Data值=%+v",
|
||||
resultStrut.Code, resultStrut.Message, resultStrut.Data, resultStrut.Data)
|
||||
|
||||
if resultStrut.Code == 200 || resultStrut.Code == 0 {
|
||||
if err = gconv.Struct(resultStrut.Data, target); err != nil { // 修复:增加err检查
|
||||
return errors.New("数据解析失败: " + err.Error())
|
||||
}
|
||||
// 添加调试日志:打印最终的target
|
||||
g.Log().Debugf(ctx, "[HTTP] 最终target: %+v", target)
|
||||
} else {
|
||||
err = errors.New(resultStrut.Message)
|
||||
}
|
||||
return
|
||||
}
|
||||
func Get(ctx context.Context, url string, headers map[string]string, target any, data ...any) (err error) {
|
||||
|
||||
42
utils/gse.go
42
utils/gse.go
@@ -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)
|
||||
|
||||
// 尝试从默认路径加载 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)
|
||||
|
||||
Reference in New Issue
Block a user