将本地结果分配给外部范围

I have this block of code. The problem is in the func, I am trying to assign to the db var in outer scope, but it ends up being declared as a local variable.

var db *sqlx.DB

func GetDatabaseConnection() *sqlx.DB {

    if db == nil {

        db, err := sqlx.Connect("postgres", "user=foo dbname=bar sslmode=disable")
        if err != nil {
            log.Fatalln(err)
        }

    }

    return db
}

my question is, regarding this line:

db, err := sqlx.Connect(...)

how can I assign db to the outer scope, and not declare it as a local varible?

var db *sqlx.DB

func GetDatabaseConnection() *sqlx.DB {

    if db == nil {
        var err error # ADD THIS LINE, AND DO = INSTEAD OF := ON NEXT LINE
        db, err = sqlx.Connect("postgres", "user=foo dbname=bar sslmode=disable")
        if err != nil {
            log.Fatalln(err)
        }

    }

    return db
}