代码拉取完成,页面将自动刷新
package influxdb
import (
"context"
"crypto/tls"
"log"
"time"
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
"github.com/influxdata/influxdb-client-go/v2/api"
)
var client influxdb2.Client = nil
type InfluxdbOptions struct {
token string
url string
org string
bucket string
}
type InfluxDbClient struct {
InfluxdbOptions
client influxdb2.Client
}
func NewClient(opts *InfluxdbOptions) *InfluxDbClient {
// Create a new client using an InfluxDB server base URL and an authentication token
if client == nil {
token := opts.token
url := opts.url
client = influxdb2.NewClientWithOptions(url, token,
influxdb2.DefaultOptions().
SetTLSConfig(&tls.Config{
InsecureSkipVerify: true,
}))
}
return &InfluxDbClient{
InfluxdbOptions: *opts,
client: client,
}
}
func (i *InfluxDbClient) SendToInfluxdb(measurement string, ts time.Time, tags map[string]string, fields map[string]interface{}) {
org := i.org
bucket := i.bucket
writeAPI := i.client.WriteAPIBlocking(org, bucket)
point := influxdb2.NewPoint(measurement, tags, fields, ts)
if err := writeAPI.WritePoint(context.Background(), point); err != nil {
log.Println("SendToInfluxdb err:" + err.Error())
}
}
func (i *InfluxDbClient) RunQuery(query string) (*api.QueryTableResult, error) {
org := i.org
queryAPI := i.client.QueryAPI(org)
return queryAPI.Query(context.Background(), query)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。