Help Center/
GeminiDB/
GeminiDB Influx API/
Working with GeminiDB Influx API/
Connecting to an Instance/
Connecting to an Instance Using Program Code/
Connecting to an Instance Using Go
Updated on 2024-10-08 GMT+08:00
Connecting to an Instance Using Go
This section describes how to connect to a GeminiDB Influx instance using the Go programming language.
Prerequisites
- You have downloaded the client code from the InfluxDB open-source project website.
Example Code for Accessing an Instance Using a Non-SSL Connection
package main import ( "fmt" _ "github.com/influxdata/influxdb1-client" // this is important because of the bug in go mod client "github.com/influxdata/influxdb1-client/v2" "os" ) func main(){ c, err := client.NewHTTPClient(client.HTTPConfig{ Addr: "http://ip:port", // There will be security risks if the username and password used for authentication are directly written into code. Store the username and password in ciphertext in the configuration file or environment variables. // In this example, the username and password are stored in the environment variables. Before running this example, set environment variables EXAMPLE_USERNAME_ENV and EXAMPLE_PASSWORD_ENV as needed. username = os.Getenv("EXAMPLE_USERNAME_ENV"), password = os.Getenv("EXAMPLE_PASSWORD_ENV"), Username: username, Password: password, }) if err != nil { fmt.Println("Error creating InfluxDB Client: ", err.Error()) } q := client.NewQuery("select * from cpu","db0","ns") if response, err := c.Query(q); err == nil && response.Error() == nil { fmt.Println("the result is: ",response.Results) } }
Parent topic: Connecting to an Instance Using Program Code
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot