I want to create a class that takes a sql connection, and then I can write methods to return data from my database.
func main() {
db := dbConnect()
defer db.Close()
// pass the db to my dbservice.go somehow?
}
Then in my handlers (for a web app) I want to be able to do:
var userKey, err := dbService.getUserKey(123)
Do I just create a file like dbservice.go and then create structs that represent my return values, and then do:
func (mystruct *MyStruct) GetUserKey(id int64) (key string, err error) {
//
}
Also, how do I pass the db to this in my main so it can use the database connection?