Remove check_error and let OpenSqliteDB return errors instead.

This commit is contained in:
A. Svensson 2016-04-22 15:12:28 +02:00
parent bcbebd4ddb
commit 6a35357b2a
3 changed files with 18 additions and 13 deletions

View File

@ -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() {

View File

@ -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()
}

16
ss13.go
View File

@ -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()