|
|
|
package influxdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
_ "fmt"
|
|
|
|
|
|
|
|
_ "github.com/influxdata/influxdb-client-go/v2"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DBClient struct {
|
|
|
|
URL string `mapstructure:"url"`
|
|
|
|
Org string `mapstructure:"org,omitempty`
|
|
|
|
Bucket string `mapstructure:"bucket,omitempty"`
|
|
|
|
Token string `mapstructure:"token,omitempty"`
|
|
|
|
// Client *influxdb2.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
type DBAdmin struct {
|
|
|
|
// struct for admin methods
|
|
|
|
*DBClient
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDBClient(conf *viper.Viper) (*DBClient, error) {
|
|
|
|
|
|
|
|
db := &DBClient{}
|
|
|
|
// grabbing config vals
|
|
|
|
err := conf.UnmarshalKey("db", db)
|
|
|
|
return db, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDBAdmin(conf *viper.Viper) (*DBAdmin, error) {
|
|
|
|
admin := &DBAdmin{}
|
|
|
|
var err error
|
|
|
|
// creating client
|
|
|
|
admin.DBClient, err = NewDBClient(conf)
|
|
|
|
return admin, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// base level funcs
|
|
|
|
func (d *DBClient) Start() {
|
|
|
|
// connect to DB
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *DBAdmin) GetReactorClient(id int) (url, bucket, org, token string, err error) {
|
|
|
|
// given an id returns
|
|
|
|
// (url, org, bucket, token, error) for said id
|
|
|
|
/*
|
|
|
|
client := influxdb2.NewClient(d.URL, d.Token)
|
|
|
|
defer client.Close()
|
|
|
|
bucket, err := client.BucketsAPI().FindBucketByName(context.Background(), id)
|
|
|
|
if err != nil {
|
|
|
|
return "", "", err
|
|
|
|
}
|
|
|
|
if d.ReactorExists(id) {
|
|
|
|
// get corresponding reactor token and bucket
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
url = d.URL
|
|
|
|
org = d.Org
|
|
|
|
err = errors.New("Unimpl")
|
|
|
|
return
|
|
|
|
}
|