云数据库 GAUSSDB NOSQL-通过Go语言连接实例:使用默认SSL证书连接实例的示例代码

时间:2023-11-10 12:13:26

使用默认SSL证书连接实例的示例代码

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"

)

func main(){
    c, err := client.NewHTTPClient(client.HTTPConfig{
        Addr: "https://ip:port",
        Username:"******",
        Password:"******",
        InsecureSkipVerify: true, // true表示不验证服务端的信息,可能存在被攻击的风险,建议设为false,具体请参见使用CCM私有证书连接实例的示例代码。
    })
    if err != nil {
        fmt.Println("Error creating InfluxDB Client: ", err.Error())
    }
    q := client.NewQuery("select * from cpu","databases","ns")
    if response, err := c.Query(q); err == nil && response.Error() == nil {
        fmt.Println(response.Results)
    }
}
support.huaweicloud.com/productdesc-nosql/nosql_09_0073.html