From bc39ba8cee293e2b962970fd5a3e661c24fa4120 Mon Sep 17 00:00:00 2001 From: Justin T <37750742+jtieri@users.noreply.github.com> Date: Fri, 13 Dec 2019 01:17:28 -0600 Subject: [PATCH] update main Update main to initialize connection with the database. Also, main now has some better output for where the flow of the program is. --- habbgo/main.go | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/habbgo/main.go b/habbgo/main.go index a81519f..3b342d9 100644 --- a/habbgo/main.go +++ b/habbgo/main.go @@ -1,16 +1,37 @@ package main import ( + "database/sql" + _ "github.com/go-sql-driver/mysql" + "github.com/jtieri/HabbGo/habbgo/config" "github.com/jtieri/HabbGo/habbgo/server" - "github.com/jtieri/HabbGo/habbgo/utils" "log" + "strconv" ) func main() { - //log.Println(string(encoding.EncodeB64(206, 2))) log.Println("Booting up HabbGo... ") - config := utils.LoadConfig() - gameServer := server.New(&config) + + log.Println("Loading config file... ") + c := config.LoadConfig() + + log.Println("Attempting to make connection with the database... ") + db, err := sql.Open("mysql", c.Database.User+":"+c.Database.Password+"@tcp"+ + "("+c.Database.Host+":"+strconv.Itoa(int(c.Database.Port))+")"+"/"+c.Database.Name) + + if err != nil { + log.Fatal(err) + } + + err = db.Ping() + if err != nil { + log.Fatalf("Failed to connect to database %v at %v:%v %v", c.Database.Name, c.Database.Host, c.Database.Port, err) + } + defer db.Close() + log.Printf("Successfully connected to database %v at %v:%v ", c.Database.Name, c.Database.Host, c.Database.Port) + + log.Println("Starting the game server... ") + gameServer := server.New(&c, db) gameServer.Start() defer gameServer.Stop() }