Looking for example in go-lang for binding the Influx-Db

Hello everybody.

Just wondering if someone knows any link (or article) how to bind the Influx DB in go-lang in the ctrlX Core environment?

The article I found is using the NodeRed and Telegraf Apps:

/ctrlx-automation-how-tos-qmglrz33/post/getting-started-with-influxdb-on-ctrlx-core-G3RGwcMjZH9IKJ7

Required is direct binding of the database in the go-lang and App-Builder-Environment for ctrlX Core.

In www there are some examples how to use the Influx DB with go-lang, but the examples don't work in ctrlX Core environment - I guess because of some restriction (firewall?) in port and so on, as well as some unmatched environment variable in Ubuntu.

Any information is highly appreciated. Thanks.

ย 

Best reply by nickH

Hiย StreetCruiser,ย 

I'm happy that you managed to write to the influxDB. ๐Ÿ™‚

I looked at the influxdb go client on GitHub a little bit deeper. I found the solution for your problem in the section queries (link).ย 

You can use result.Next() to iterate over the query response.ย 

result, err := queryAPI.Query(context.Background(), `from(bucket: "TestBucket") |> range(start: -1h) |> filter(fn: (r) => r["_measurement"] == "metric") |> filter(fn: (r) => r["_field"] == "sampleValue")`)
if err == nil {
	// next() to iterate over query result lines
	for result.Next() {
		// print out result
		fmt.Printf("row: %s\n", result.Record().String())
	}
	if result.Err() != nil {
		fmt.Printf("Query error: %s\n", result.Err().Error())
	}

ย 

Note: you may have to modify the queryย for your need.ย 

Best regards,ย 

Nick

View original
10 replies