package influxdb import ( _ "fmt" _ "github.com/influxdata/influxdb-client-go/v2" "github.com/spf13/viper" ) type DBInfo 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 *DBInfo Config *viper.Viper } type DBClient struct { // struct for client methods *DBInfo Config *viper.Viper } func NewDBInfo(config *viper.Viper) (*DBInfo, error) { db := &DBInfo{} // grabbing config vals err := config.UnmarshalKey("db", db) return db, err } func NewDBClient(config *viper.Viper) (*DBClient, error) { client := &DBClient{Config: config} // grabbing config vals var err error client.DBInfo, err = NewDBInfo(config) return client, err } func NewDBAdmin(config *viper.Viper) (*DBAdmin, error) { admin := &DBAdmin{Config: config} var err error // creating client admin.DBInfo, err = NewDBInfo(config) return admin, err } // base level funcs func (d *DBInfo) Start() error { // connect to DB based w/ info return nil } 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 token = "" bucket = "" //err = errors.New("Unimpl") err = nil return }