I am working on a web application in Golang. Where should I open my database? In main
or in http.HandleFunc
?
func main(){
db, _ := sql.Open("driver",dbinfo)
// other http.HandleFunc goes here
}
or
func AHandler(w http.ResponseWriter, r *http.Request) {
db, _ := sql.Open("driver",dbinfo)
//it will open a new database connection for every new request!
}