refactor: 标签不可移动,资源选择优化等

This commit is contained in:
meilin.huang
2025-10-07 15:41:19 +08:00
parent c4d52ce47a
commit 4ac57cd140
23 changed files with 172 additions and 258 deletions

View File

@@ -121,8 +121,8 @@ func Errorf(format string, args ...any) {
Log(context.Background(), slog.LevelError, fmt.Sprintf(format, args...))
}
// 错误记录并将堆栈信息添加至msg里默认记录10个堆栈信息
func ErrorTrace(msg string, err any) {
// ErrorTraceContext 错误记录并将堆栈信息添加至msg里默认记录10个堆栈信息
func ErrorTraceContext(ctx context.Context, msg string, err any) {
errMsg := ""
switch t := err.(type) {
case error:
@@ -132,7 +132,12 @@ func ErrorTrace(msg string, err any) {
default:
errMsg = fmt.Sprintf("%v", t)
}
Log(context.Background(), slog.LevelError, fmt.Sprintf(msg+"\n%s\n%s", errMsg, runtimex.StackStr(2, 20)))
Log(ctx, slog.LevelError, fmt.Sprintf(msg+"\n%s\n%s", errMsg, runtimex.StackStr(2, 20)))
}
// ErrorTrace 错误记录并将堆栈信息添加至msg里默认记录10个堆栈信息
func ErrorTrace(msg string, err any) {
ErrorTraceContext(context.Background(), msg, err)
}
func ErrorWithFields(ctx context.Context, msg string, mapFields map[string]any) {

View File

@@ -49,8 +49,9 @@ func Error(bizerr *errorx.BizError) *Result {
}
// 返回服务器错误Result
func ServerError() *Result {
return Error(errorx.ServerError)
func ServerError(msg string) *Result {
serverErr := errorx.NewBizCode(errorx.ServerError.Code(), msg)
return Error(serverErr)
}
func TokenError() *Result {

View File

@@ -1,7 +1,9 @@
package req
import (
"cmp"
"context"
"fmt"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/contextx"
"mayfly-go/pkg/errorx"
@@ -109,8 +111,8 @@ func (rc *Ctx) res() {
case *errorx.BizError:
rc.JSONRes(http.StatusOK, model.Error(t))
default:
logx.ErrorTrace("服务器错误", t)
rc.JSONRes(http.StatusOK, model.ServerError())
logx.ErrorTrace("server error", t)
rc.JSONRes(http.StatusOK, model.ServerError(fmt.Sprintf("server error [%d-%s]", errorx.ServerError.Code(), cmp.Or(contextx.GetTraceId(rc.MetaCtx), "none"))))
}
return
}

View File

@@ -53,7 +53,7 @@ func Ip2Region(ip string) string {
}
// 2、用全局的 vIndex 创建带 VectorIndex 缓存的查询对象。
searcher, err := xdb.NewWithVectorIndex(ip2RegionDbPath, vectorIndex)
searcher, err := xdb.NewWithVectorIndex(xdb.IPv4, ip2RegionDbPath, vectorIndex)
if err != nil {
logx.Errorf("failed to create searcher with vector index: %s\n", err)
return ""