尝试给上报到elasticsearch的文档加_id

This commit is contained in:
zhangkun 2024-12-03 23:32:58 +08:00
parent 193ea03604
commit 95997cd79d
2 changed files with 13 additions and 1 deletions

View File

@ -6,6 +6,8 @@ import (
"fmt" "fmt"
"math/rand" "math/rand"
// "os" // "os"
"crypto/sha256"
"encoding/hex"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -172,11 +174,21 @@ func Daoxu(arr []interface{}) {
arr[length-1-i] = temp arr[length-1-i] = temp
} }
} }
func hashString(input string) string {
// 计算SHA-256哈希值
hash := sha256.Sum256([]byte(input))
// 转换为十六进制字符串
hashHex := hex.EncodeToString(hash[:])
// 返回前20位
return hashHex[:20]
}
func (cl *Candle) ToStruct(core *Core) error { func (cl *Candle) ToStruct(core *Core) error {
// cl.Timestamp // cl.Timestamp
cl.Id = cl.InstId + "." + cl.Period + "." + cl.Data[0].(string) str := cl.InstId + "." + cl.Period + "." + cl.Data[0].(string)
cl.Id = hashString(str)
// 将字符串转换为 int64 类型的时间戳 // 将字符串转换为 int64 类型的时间戳
ts, err := strconv.ParseInt(cl.Data[0].(string), 10, 64) ts, err := strconv.ParseInt(cl.Data[0].(string), 10, 64)
if err != nil { if err != nil {

BIN
tunas

Binary file not shown.