I declare my database connection in my main
package, sort of like this:
package main
var Db *sql.DB
func main() {
var err error
db, err = sql.Open("postgres", "stuff...")
// error handling and more app stuff
}
To begin with I had all of my code in the main
package and I could access the database connection from other files. However, I want to separate code into packages, and now the Db
variable isn't visible anymore.
Is it possible to share it across packages or do I have to add it as a parameter to whatever calls to other packages I have in my main
function?