Go: refactor (#20054)

Signed-off-by: Jin Hai <[email protected]>
This commit is contained in:
Jin Hai
2026-09-29 14:17:54 +08:00
parent 921d652808
commit 72a541dd41
19 changed files with 32 additions and 94 deletions
+5 -5
View File
@@ -33,8 +33,8 @@ import (
"ragflow/internal/agent/runtime"
agenttool "ragflow/internal/agent/tool"
"ragflow/internal/channels"
native "ragflow/internal/deepdoc/native"
pdf "ragflow/internal/deepdoc/parser/pdf"
"ragflow/internal/deepdoc/native"
"ragflow/internal/deepdoc/parser/pdf"
modelModule "ragflow/internal/entity/models"
"ragflow/internal/handler"
"ragflow/internal/ingestion/knowledge_compile"
@@ -44,7 +44,7 @@ import (
"ragflow/internal/server/local"
"ragflow/internal/service"
"ragflow/internal/service/chunk"
dataset "ragflow/internal/service/dataset"
"ragflow/internal/service/dataset"
"ragflow/internal/service/document"
"ragflow/internal/service/file"
"ragflow/internal/service/nav"
@@ -682,7 +682,7 @@ func runAdmin(ctx context.Context, serverName string, args *serverArgs) error {
ginEngine := gin.New()
// Mirror Quart's merge_slashes: collapse duplicate slashes before routing.
ginEngine.RemoveExtraSlash = true
// Only honour X-Forwarded-For / X-Real-IP from the configured proxies
// Only honor X-Forwarded-For / X-Real-IP from the configured proxies
// (default: the loopback nginx bundled in the image), never from every peer.
if err := common.ConfigureTrustedProxies(ginEngine, globalConfig.GetAPIServerConfig().TrustedProxies); err != nil {
common.Fatal("Failed to configure trusted proxies", zap.Error(err))
@@ -1205,7 +1205,7 @@ func startServer(ctx context.Context, serverName string, arguments *serverArgs)
ginEngine := gin.New()
// Mirror Quart's merge_slashes: collapse duplicate slashes before routing.
ginEngine.RemoveExtraSlash = true
// Only honour X-Forwarded-For / X-Real-IP from the configured proxies
// Only honor X-Forwarded-For / X-Real-IP from the configured proxies
// (default: the loopback nginx bundled in the image), never from every
// peer. c.ClientIP() feeds the agent webhook ip_whitelist gate and the
// login audit records, so gin's trust-everything default would let any
+1 -1
View File
@@ -410,7 +410,7 @@ func evaluateClause(clause map[string]any, state *runtime.CanvasState) (bool, er
return ln < rn, nil
case ">=":
return ln >= rn, nil
case "<=":
default:
return ln <= rn, nil
}
}
+1 -1
View File
@@ -113,7 +113,7 @@ func IsTransientError(err error) bool {
if code >= 500 || code == 429 {
return true
}
if code >= 400 && code < 500 {
if code >= 400 {
return false
}
}
-13
View File
@@ -268,16 +268,3 @@ func clipLine(mw, mh, x0, y0, x1, y1 int) (int, int, int, int) {
}
return x0, y0, x1, y1
}
func math_min(a, b float64) float64 {
if a < b {
return a
}
return b
}
func math_max(a, b float64) float64 {
if a > b {
return a
}
return b
}
@@ -656,7 +656,7 @@ func HeaderSetWithBlockType(rows [][]pdf.TSRCell, boxes []pdf.TextBox) map[int]b
if bt == "Nu" {
continue // numeric cell in a numeric table: ignored
}
if colHit[ri][ci] || bt != "Nu" {
if colHit[ri][ci] {
h++
}
}
+1 -1
View File
@@ -107,7 +107,7 @@ func (e *serenedbEngine) Search(ctx context.Context, req *types.SearchRequest) (
if scored && len(result.Chunks) > 1 {
sortByScore(result.Chunks)
}
if limit > 0 && len(result.Chunks) > limit {
if len(result.Chunks) > limit {
result.Chunks = result.Chunks[:limit]
}
if result.Total == 0 {
-17
View File
@@ -662,23 +662,6 @@ func cloneMap(src map[string]any) map[string]any {
return clone
}
// DEFAULT_RUNTIME is the default runtime instance with nil values.
// Configurable is nil (not an empty map) so that direct mutation via Set
// panics with nil pointer dereference rather than silently corrupting a
// shared global. Callers must use Clone() to obtain a safe copy.
// This corresponds to Python's DEFAULT_RUNTIME in runtime.py
var DEFAULT_RUNTIME = &Runtime{
TaskID: "",
NodeName: "",
Step: 0,
Configurable: nil,
CheckpointNS: "",
Context: nil,
Store: nil,
StreamWriter: nil,
Previous: nil,
}
// GetTaskID returns the task ID from config.
func GetTaskID(config map[string]interface{}) string {
if config == nil {
@@ -225,10 +225,8 @@ func (te *TracedEngine) traceEvent(ctx context.Context, event any, rootSpan trac
intSpan.SetStatus(codes.Ok, "")
intSpan.End()
case EventTypeError:
if rootSpan != nil {
rootSpan.SetStatus(codes.Error, fmt.Sprintf("%v", se.Error))
rootSpan.RecordError(se.Error)
}
rootSpan.SetStatus(codes.Error, fmt.Sprintf("%v", se.Error))
rootSpan.RecordError(se.Error)
case EventTypeTaskStart:
_, taskSpan := te.tracer.Start(ctx, SpanNodeExecute,
trace.WithSpanKind(trace.SpanKindInternal),
-23
View File
@@ -1,23 +0,0 @@
//
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package task
// Special doc_id values used in task messages (mirrors Python constants).
const (
// GRAPH_RAPTOR_FAKE_DOC_ID is the fake doc_id used for RAPTOR-generated chunks.
GRAPH_RAPTOR_FAKE_DOC_ID = "graph_raptor_fake_doc"
)
+1 -1
View File
@@ -19,7 +19,7 @@ package task
import (
"time"
indexdoc "ragflow/internal/ingestion/task/indexdoc"
"ragflow/internal/ingestion/task/indexdoc"
)
// GoldenCompareResult is the structured output used by the local golden tools.
@@ -1675,11 +1675,9 @@ func (m *InvokerSessionModel) CompleteWithTemperature(ctx context.Context, messa
return nil, err
}
reply := &ModelReply{Content: resp.Content}
if resp != nil {
reply.Usage = resp.Usage
reply.Tokens = totalOf(resp)
reply.ToolCalls = nativeToHarnessCalls(resp.ToolCalls)
}
reply.Usage = resp.Usage
reply.Tokens = totalOf(resp)
reply.ToolCalls = nativeToHarnessCalls(resp.ToolCalls)
return reply, nil
}
@@ -1724,11 +1722,9 @@ func (m *InvokerSessionModel) Complete(ctx context.Context, messages []schema.Me
return nil, err
}
reply := &ModelReply{Content: resp.Content}
if resp != nil {
reply.Usage = resp.Usage
reply.Tokens = totalOf(resp)
reply.ToolCalls = nativeToHarnessCalls(resp.ToolCalls)
}
reply.Usage = resp.Usage
reply.Tokens = totalOf(resp)
reply.ToolCalls = nativeToHarnessCalls(resp.ToolCalls)
return reply, nil
}
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"testing"
"ragflow/internal/common"
kvrocks "ragflow/internal/engine/kvrocks"
"ragflow/internal/engine/kvrocks"
)
type roundTripFunc func(*http.Request) (*http.Response, error)
@@ -24,7 +24,7 @@ import (
"ragflow/internal/common"
"ragflow/internal/engine/types"
kccommon "ragflow/internal/ingestion/component/knowledge_compiler/common"
knowledge_compile "ragflow/internal/ingestion/knowledge_compile"
"ragflow/internal/ingestion/knowledge_compile"
"go.uber.org/zap"
)
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"ragflow/internal/common"
"ragflow/internal/dao"
kvrocks "ragflow/internal/engine/kvrocks"
"ragflow/internal/engine/kvrocks"
"ragflow/internal/entity"
"go.uber.org/zap"
+5 -4
View File
@@ -21,6 +21,11 @@ import (
"context"
"errors"
"fmt"
"ragflow/internal/common"
"ragflow/internal/entity"
"ragflow/internal/entity/models"
"ragflow/internal/utility"
"slices"
"sort"
"strconv"
@@ -30,14 +35,10 @@ import (
"go.uber.org/zap"
"gorm.io/gorm"
"ragflow/internal/common"
"ragflow/internal/dao"
"ragflow/internal/engine"
enginetypes "ragflow/internal/engine/types"
"ragflow/internal/entity"
models "ragflow/internal/entity/models"
"ragflow/internal/service/nlp"
"ragflow/internal/utility"
)
const (
+1 -1
View File
@@ -46,7 +46,7 @@ import (
"ragflow/internal/common"
"ragflow/internal/dao"
"ragflow/internal/entity"
models "ragflow/internal/entity/models"
"ragflow/internal/entity/models"
"go.uber.org/zap"
"gorm.io/gorm"
+2 -2
View File
@@ -61,9 +61,9 @@ import (
"ragflow/internal/common"
"ragflow/internal/dao"
kvrocks "ragflow/internal/engine/kvrocks"
"ragflow/internal/engine/kvrocks"
"ragflow/internal/entity"
models "ragflow/internal/entity/models"
"ragflow/internal/entity/models"
"ragflow/internal/utility"
"gorm.io/gorm"
+1 -5
View File
@@ -1669,11 +1669,7 @@ func restAPIQuoteString(s string) string {
b.WriteString(`\f`)
default:
if r < 0x20 || r == 0x7f {
if r < 0x100 {
b.WriteString(fmt.Sprintf(`\x%02x`, r))
} else {
b.WriteString(fmt.Sprintf(`\u%04x`, r))
}
b.WriteString(fmt.Sprintf(`\x%02x`, r))
} else {
b.WriteRune(r)
}
+2 -2
View File
@@ -315,11 +315,11 @@ func (m *sentencePieceModel) parseNormalizerSpec(raw []byte) error {
m.addDummyPrefix = on
case 4:
m.removeExtraWhitespaces = on
case 5:
default:
m.escapeWhitespaces = on
}
default:
if err := r.skip(wire); err != nil {
if err = r.skip(wire); err != nil {
return fmt.Errorf("sentencepiece: normalizer_spec: %w", err)
}
}