I am currently trying to migrate my application to IBM cloud functions, but one issue that I am facing is keeping the Postgresql DB from beeing reconnected every time an action is invoked.
I have found very little information about how to reuse a DB connection in Go, and the solutions I have tried (keeping the database handler in a global variable) does not work.
Would anyone be able to point me to the right doc?
Thanks,
-Thomas
PS: Here is a snippet of code that illustrates the way I tried:
func Storage() Storager {
once.Do(func() {
db := InitDB()
println("Initiating DB...")
s = &storage{
db: db,
}
})
return s
}
// This is declared as a global variable in main
var s = storage.Storage()