I'm using the MySQL driver for Golang provided here
https://github.com/go-sql-driver/mysql
One of the things I'm trying to do is store the database variable in a global connection. According to the documentation, sql.Open() is supposed to return a pointer to a DB struct, so I tried storing it as
var db *DB
However, that resulted in the error
undefined: DB
The next thing I tried was to look at the source code for the MySQL driver, and I found a snippet of code here https://github.com/go-sql-driver/mysql/blob/master/driver.go
func (d MySQLDriver) Open(dsn string) (driver.Conn, error) {
So, I tried to save the variable as driver.Conn - however, I was unable to (incorrect imports). I wasn't able to import driver either.
The last thing I tried was to use reflect to bring the name of the variable to light
package main
import (
"fmt"
"reflect"
)
import "database/sql"
import _ "github.com/go-sql-driver/mysql"
func main() {
db, _ := sql.Open("mysql", "root:password@/Tracker")
yt := reflect.TypeOf(db).Kind()
fmt.Printf("%T: %s\n", yt, yt)
}
Unfortunately, that didn't work either - it shows up as pointer, and not the type of variable it's actually pointing to.
I'm at a loss as to how to figure it out now. Thanks in advance for your help!