Remove check_error and let OpenSqliteDB return errors instead.
This commit is contained in:
parent
bcbebd4ddb
commit
6a35357b2a
@ -13,11 +13,12 @@ type DB struct {
|
|||||||
*gorm.DB
|
*gorm.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func OpenSqliteDB(args ...interface{}) *DB {
|
func OpenSqliteDB(args ...interface{}) (*DB, error) {
|
||||||
var e error
|
|
||||||
db, e := gorm.Open("sqlite3", args...)
|
db, e := gorm.Open("sqlite3", args...)
|
||||||
check_error(e)
|
if LogError(e) {
|
||||||
return &DB{&db}
|
return nil, e
|
||||||
|
}
|
||||||
|
return &DB{&db}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) InitSchema() {
|
func (db *DB) InitSchema() {
|
||||||
|
|||||||
@ -17,12 +17,6 @@ func LogError(err error) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func check_error(err error) {
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("ERROR ", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ResetNow() {
|
func ResetNow() {
|
||||||
now = time.Now()
|
now = time.Now()
|
||||||
}
|
}
|
||||||
|
|||||||
16
ss13.go
16
ss13.go
@ -68,13 +68,18 @@ func run_server(c *cli.Context) {
|
|||||||
fmt.Printf("Listening on %s.\n\n", c.GlobalString("addr"))
|
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{
|
instance := &ss13.Instance{
|
||||||
Debug: c.GlobalBool("debug"),
|
Debug: c.GlobalBool("debug"),
|
||||||
DB: ss13.OpenSqliteDB(c.GlobalString("database")),
|
DB: db,
|
||||||
PrivServersFile: c.GlobalString("private-servers"),
|
PrivServersFile: c.GlobalString("private-servers"),
|
||||||
}
|
}
|
||||||
instance.Init()
|
instance.Init()
|
||||||
e := instance.Serve(c.GlobalString("addr"))
|
e = instance.Serve(c.GlobalString("addr"))
|
||||||
ss13.LogError(e)
|
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{
|
instance := &ss13.Instance{
|
||||||
Debug: c.GlobalBool("debug"),
|
Debug: c.GlobalBool("debug"),
|
||||||
DB: ss13.OpenSqliteDB(c.GlobalString("database")),
|
DB: db,
|
||||||
PrivServersFile: c.GlobalString("private-servers"),
|
PrivServersFile: c.GlobalString("private-servers"),
|
||||||
}
|
}
|
||||||
instance.Init()
|
instance.Init()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user