问题内容 我想用这样的签名写点InfluxDB: { "_field": "some_uuid", "_value": float64, "_time": "2006-01-02T15
我想用这样的签名写点InfluxDB:
{
"_field": "some_uuid",
"_value": float64,
"_time": "2006-01-02T15:04:05.000Z"
}
但是 uuid 写入“field”键而不是“_field”,并且“_field”键具有默认值 - “value”。 我该如何修复它?
这是我的示例代码:
import (
"fmt"
influxdb2 "GitHub.com/influxdata/influxdb-client-Go/v2"
"time"
)
type TagData struct {
TagId string `JSON:"tag_id"`
Value float64 `json:"value"`
Timestamp string `json:"timestamp"`
}
func main() {
inflClient := influxdb2.NewClient("my_url", "my_token")
writeapi := inflClient.WriteAPI("my_org", "my_bucket")
data := TagData{
TagId: "d8f623a9-c255-4e0d-9c2f-126056875cef",
Value: 300,
Timestamp: "2023-12-11T15:35:42.343Z",
}
parsedTime, err := time.Parse("2006-01-02T15:04:05.000Z", data.Timestamp)
if err != nil {
fmt.Println("Error parsing time:", err)
return
}
point := influxdb2.NewPointWithMeasurement("data").
AddTag("field", data.TagId).
AddField("value", data.Value).
SetTime(parsedTime.UTC())
writeAPI.WritePoint(point)
writeAPI.Flush()
inflClient.Close()
}
如果有人遇到同样的问题 - 可能的解决方案是:
point := influxdb2.NewPointWithMeasurement("your_measurement").
AddField(data.TagId, data.Value).
SetTime(parsedTime.UTC())
point := influxdb2.NewPoint("your_measurement",
map[string]string{},
map[string]interface{}{data.TagId: data.Value},
parsedTime.UTC())
--结束END--
本文标题: Golang InfluxDB 客户端使用 _field 键写入点
本文链接: https://lsjlt.com/news/561507.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-04-05
2024-04-05
2024-04-05
2024-04-04
2024-04-05
2024-04-05
2024-04-05
2024-04-05
2024-04-04
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0