我想用這樣的簽章寫點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())
以上是Golang InfluxDB 用戶端使用 _field 鍵寫入點的詳細內容。更多資訊請關注PHP中文網其他相關文章!