As golang does not support circular dependencies, and I am only just starting in golang. I've run into a little wall with my connection variable, I am using the gorm driver, and MySQL as my database engine.
And I'm trying to pass on the connection variable to the next function my program calls, which is in another file. AchFactory.go
fmt.Println(">Loading Achievements")
Start.DB.HasTable("achievements")
Start.DB.Select("id", "group_name", "category", "level", "reward_pixels", "reward_points", "progress_needed", "game_id").Find("achievements")
fmt.Println(">Found Schema")
Start.go
var DB *gorm.DB
func Initi() {
fmt.Println("Initating!")
Connect()
}
func Connect() {
var err error
DB, err = gorm.Open("mysql", config.MYSQL_USER+":"+config.MYSQL_PASS+"@/"+config.MYSQL_DB+"?charset=utf8&parseTime=True&loc=Local")
if err != nil {
panic(err)
DB.Close()
}
fmt.Println(">Connection Succesful")
fmt.Println(">Test Query Starting")
TestQ()
}
func TestQ() {
DB.HasTable("tests")
fmt.Println(">Query Succesful!")
AchManager.GetAch()
}
Would just like to know what i've done wrong so i can prevent this error in the future. Thank you :)