In the following snippet
package ...
var Conn *sql.DB // outer Conn
func Init(user, pwd, dbname string, port int) {
Conn, err := sql.Open("postgres", "... args") // inner Conn
// ..
}
the inner Conn
is a new variable and outer Conn
will remain null.
By explicitly defining err
and replacing the short variable definition with assignment it seems to properly init the outer Conn
variable
var err error
Conn, err = sql.Open("postgres", "... args") // inner Conn
Is there a simpler way to specify the inner Conn
should not really be a scoped variable but instead the global Conn
variable? I'm thinking something like package.Conn
, but that's invalid inside the package itself.