diff --git a/src/db.go b/src/db.go index 3b9a36d..1559701 100644 --- a/src/db.go +++ b/src/db.go @@ -13,11 +13,12 @@ type DB struct { *gorm.DB } -func OpenSqliteDB(args ...interface{}) *DB { - var e error +func OpenSqliteDB(args ...interface{}) (*DB, error) { db, e := gorm.Open("sqlite3", args...) - check_error(e) - return &DB{&db} + if LogError(e) { + return nil, e + } + return &DB{&db}, nil } func (db *DB) InitSchema() { diff --git a/src/utils.go b/src/utils.go index 8a6ce8b..28091b2 100644 --- a/src/utils.go +++ b/src/utils.go @@ -17,12 +17,6 @@ func LogError(err error) bool { return false } -func check_error(err error) { - if err != nil { - log.Fatal("ERROR ", err) - } -} - func ResetNow() { now = time.Now() } diff --git a/ss13.go b/ss13.go index 21ccccd..d038b79 100644 --- a/ss13.go +++ b/ss13.go @@ -68,13 +68,18 @@ func run_server(c *cli.Context) { fmt.Printf("Listening on %s.\n\n", c.GlobalString("addr")) } + db, e := ss13.OpenSqliteDB(c.GlobalString("database")) + if ss13.LogError(e) { + return + } + instance := &ss13.Instance{ Debug: c.GlobalBool("debug"), - DB: ss13.OpenSqliteDB(c.GlobalString("database")), + DB: db, PrivServersFile: c.GlobalString("private-servers"), } instance.Init() - e := instance.Serve(c.GlobalString("addr")) + e = instance.Serve(c.GlobalString("addr")) ss13.LogError(e) } @@ -88,9 +93,14 @@ func update_stats(c *cli.Context) { } } + db, e := ss13.OpenSqliteDB(c.GlobalString("database")) + if ss13.LogError(e) { + return + } + instance := &ss13.Instance{ Debug: c.GlobalBool("debug"), - DB: ss13.OpenSqliteDB(c.GlobalString("database")), + DB: db, PrivServersFile: c.GlobalString("private-servers"), } instance.Init()