Go: fix warnings (#17738)

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-08-03 21:30:01 +08:00
committed by GitHub
parent d357eea8ef
commit 86021932ae
103 changed files with 437 additions and 439 deletions

View File

@@ -122,12 +122,13 @@ func TestElasticsearchGetFieldsEmptyAndSkippedIDs(t *testing.T) {
if _, ok := got["missing-id.md"]; ok {
t.Fatalf("chunk without id should be skipped: %#v", got)
}
if fallbackMap, ok := got["fallback-chunk"]; !ok {
fallbackMap, ok := got["fallback-chunk"]
if !ok {
t.Fatalf("GetFields keys=%v, want fallback-chunk", got)
} else {
assertEqual(t, fallbackMap["id"], "fallback-chunk")
assertEqual(t, fallbackMap["docnm_kwd"], "fallback.md")
}
assertEqual(t, fallbackMap["id"], "fallback-chunk")
assertEqual(t, fallbackMap["docnm_kwd"], "fallback.md")
}
func TestElasticsearchGetAggregationSplitsCountsAndSorts(t *testing.T) {

View File

@@ -68,7 +68,7 @@ func NewEngine(esConfig config.ElasticsearchConfig) (*Engine, error) {
defer res.Body.Close()
if res.IsError() {
return nil, fmt.Errorf("Elasticsearch returned error: %s", res.Status())
return nil, fmt.Errorf("elasticsearch returned error: %s", res.Status())
}
engine := &Engine{

View File

@@ -274,7 +274,7 @@ func (e *Engine) InsertChunks(ctx context.Context, chunks []map[string]interface
db, release, err := e.client.checkoutDatabase(ctx, "chunk.go")
if err != nil {
return nil, fmt.Errorf("Failed to get database: %w", err)
return nil, fmt.Errorf("failed to get database: %w", err)
}
defer release()
@@ -283,7 +283,7 @@ func (e *Engine) InsertChunks(ctx context.Context, chunks []map[string]interface
// Table doesn't exist, try to create it
errMsg := strings.ToLower(err.Error())
if !strings.Contains(errMsg, "not found") && !strings.Contains(errMsg, "doesn't exist") {
return nil, fmt.Errorf("Failed to get table %s: %w", tableName, err)
return nil, fmt.Errorf("failed to get table %s: %w", tableName, err)
}
// Infer vector size from chunks
@@ -313,12 +313,12 @@ func (e *Engine) InsertChunks(ctx context.Context, chunks []map[string]interface
// Create table
if err := e.createChunkStoreWithDB(db, baseName, datasetID, vectorSize, parserID); err != nil {
return nil, fmt.Errorf("Failed to create table: %w", err)
return nil, fmt.Errorf("failed to create table: %w", err)
}
table, err = db.GetTable(tableName)
if err != nil {
return nil, fmt.Errorf("Failed to get table after creation: %w", err)
return nil, fmt.Errorf("failed to get table after creation: %w", err)
}
}
@@ -326,7 +326,7 @@ func (e *Engine) InsertChunks(ctx context.Context, chunks []map[string]interface
var embeddingCols [][2]interface{}
colsResp, err := table.ShowColumns()
if err != nil {
return nil, fmt.Errorf("Failed to get columns: %w", err)
return nil, fmt.Errorf("failed to get columns: %w", err)
}
result, ok := colsResp.(*infinity.QueryResult)
if !ok {
@@ -379,14 +379,14 @@ func (e *Engine) InsertChunks(ctx context.Context, chunks []map[string]interface
// Insert chunks to dataset
_, err = table.Insert(insertChunks)
if err != nil {
return nil, fmt.Errorf("Failed to insert chunks to dataset: %w", err)
return nil, fmt.Errorf("failed to insert chunks to dataset: %w", err)
}
common.Info("InfinityConnection.InsertChunks result", zap.String("tableName", tableName), zap.Int("count", len(insertChunks)))
return []string{}, nil
}
// UpdateChunks updates chunks in a dataset table
// UpdateChunks updates chunks in a dataset
// Table name format: {baseName}_{datasetID}
func (e *Engine) UpdateChunks(ctx context.Context, condition map[string]interface{}, newValue map[string]interface{}, baseName string, datasetID string) error {
tableName := buildChunkTableName(baseName, datasetID)
@@ -394,7 +394,7 @@ func (e *Engine) UpdateChunks(ctx context.Context, condition map[string]interfac
db, release, err := e.client.checkoutDatabase(ctx, "chunk.go")
if err != nil {
return fmt.Errorf("Failed to get database: %w", err)
return fmt.Errorf("failed to get database: %w", err)
}
defer release()
@@ -406,7 +406,7 @@ func (e *Engine) UpdateChunks(ctx context.Context, condition map[string]interfac
if strings.Contains(errMsg, "not found") || strings.Contains(errMsg, "doesn't exist") {
return nil
}
return fmt.Errorf("Failed to get table %s: %w", tableName, err)
return fmt.Errorf("failed to get table %s: %w", tableName, err)
}
// Get table columns
@@ -416,7 +416,7 @@ func (e *Engine) UpdateChunks(ctx context.Context, condition map[string]interfac
})
colsResp, err := table.ShowColumns()
if err != nil {
return fmt.Errorf("Failed to get columns: %w", err)
return fmt.Errorf("failed to get columns: %w", err)
}
result, ok := colsResp.(*infinity.QueryResult)
if ok {
@@ -534,7 +534,7 @@ func (e *Engine) UpdateChunks(ctx context.Context, condition map[string]interfac
common.Info(fmt.Sprintf("INFINITY update: table=%s, filter=%s, newValue=%v", tableName, filter, newValue))
_, err = table.Update(filter, newValue)
if err != nil {
return fmt.Errorf("Failed to update chunks: %w", err)
return fmt.Errorf("failed to update chunks: %w", err)
}
common.Info("InfinityConnection.UpdateChunks completes", zap.String("tableName", tableName))
@@ -553,7 +553,7 @@ func (e *Engine) AdjustChunkPagerank(ctx context.Context, baseName, chunkID, dat
ctx = context.Background()
}
if e.client == nil || e.client.pool == nil {
return fmt.Errorf("Infinity client not initialized")
return fmt.Errorf("infinity client not initialized")
}
tableName := buildChunkTableName(baseName, datasetID)
@@ -1214,7 +1214,7 @@ func (e *Engine) Search(ctx context.Context, req *types.SearchRequest) (*types.S
// GetChunk gets a chunk by ID
func (e *Engine) GetChunk(ctx context.Context, tableName, chunkID string, datasetIDs []string) (interface{}, error) {
if e.client == nil || e.client.pool == nil {
return nil, fmt.Errorf("Infinity client not initialized")
return nil, fmt.Errorf("infinity client not initialized")
}
common.Info("Infinity get chunk start",

View File

@@ -173,7 +173,7 @@ func NewInfinityClient(cfg config.InfinityConfig) (*infinityClient, error) {
}
}
if err != nil {
return nil, fmt.Errorf("Failed to connect to Infinity after 120s: %w", err)
return nil, fmt.Errorf("failed to connect to Infinity after 120s: %w", err)
}
client := &infinityClient{
@@ -243,12 +243,12 @@ func (c *infinityClient) WaitForHealthy(ctx context.Context, timeout time.Durati
}
time.Sleep(5 * time.Second)
}
return fmt.Errorf("Infinity not healthy after %v", timeout)
return fmt.Errorf("infinity not healthy after %v", timeout)
}
func (c *infinityClient) checkoutConn(ctx context.Context, caller string) (*infinity.InfinityConnection, func(), error) {
if c == nil || c.pool == nil {
return nil, nil, fmt.Errorf("Infinity client not initialized")
return nil, nil, fmt.Errorf("infinity client not initialized")
}
ctx, cancel := ensureDeadline(ctx, defaultOperationTimeout)
conn, err := c.pool.GetContext(ctx)
@@ -365,7 +365,7 @@ func NewEngine(infinityConfig config.InfinityConfig) (*Engine, error) {
// Wait for Infinity to be healthy
if err = client.WaitForHealthy(context.Background(), 120*time.Second); err != nil {
return nil, fmt.Errorf("Infinity not healthy: %w", err)
return nil, fmt.Errorf("infinity not healthy: %w", err)
}
// MigrateDB creates the database if it doesn't exist
@@ -389,7 +389,7 @@ func (e *Engine) SupportsPageRank() bool {
// Ping checks if Infinity is accessible
func (e *Engine) Ping(ctx context.Context) error {
if e.client == nil || e.client.pool == nil {
return fmt.Errorf("Infinity client not initialized")
return fmt.Errorf("infinity client not initialized")
}
conn, release, err := e.client.checkoutConn(ctx, "Ping")
if err != nil {
@@ -397,7 +397,7 @@ func (e *Engine) Ping(ctx context.Context) error {
}
defer release()
if !conn.IsConnected() {
return fmt.Errorf("Infinity not connected")
return fmt.Errorf("infinity not connected")
}
return nil
}

View File

@@ -19,6 +19,7 @@ package redis
import (
"context"
"encoding/json"
"errors"
"fmt"
"math"
"math/rand"
@@ -294,7 +295,7 @@ func (r *Client) Get(ctx context.Context, key string) (string, error) {
return "", nil
}
val, err := r.client.Get(ctx, key).Result()
if err == redis.Nil {
if errors.Is(err, redis.Nil) {
return "", nil
}
if err != nil {
@@ -327,7 +328,7 @@ func (r *Client) GetObj(ctx context.Context, key string, dest interface{}) bool
return false
}
data, err := r.client.Get(ctx, key).Result()
if err == redis.Nil {
if errors.Is(err, redis.Nil) {
return false
}
if err != nil {
@@ -675,7 +676,7 @@ func (r *Client) QueueConsumer(ctx context.Context, queueName, groupName, consum
Block: 5 * time.Second,
}).Result()
if err == redis.Nil {
if errors.Is(err, redis.Nil) {
return nil, nil
}
if err != nil {