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.
This commit is contained in:
parent
efa4e5396a
commit
bc39ba8cee
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue