From 3722c6ba790c0362052541a44a35f574e97338fd Mon Sep 17 00:00:00 2001 From: Aaron Ogle Date: Sat, 5 Jan 2019 14:59:05 -0600 Subject: [PATCH 1/2] Only check for username and password if driver type is mysql --- app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.go b/app.go index ba04dde..f43b486 100644 --- a/app.go +++ b/app.go @@ -370,7 +370,7 @@ func Serve() { app.formDecoder.RegisterConverter(sql.NullFloat64{}, converter.ConvertSQLNullFloat64) // Check database configuration - if app.cfg.Database.User == "" || app.cfg.Database.Password == "" { + if app.cfg.Database.Type == "mysql" && (app.cfg.Database.User == "" || app.cfg.Database.Password == "") { log.Error("Database user or password not set.") os.Exit(1) } From a58a756746d23bd0a93663cda0673de2cfc9c6e7 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sat, 5 Jan 2019 17:51:17 -0500 Subject: [PATCH 2/2] Use driver constants in app.go --- app.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app.go b/app.go index f43b486..dbb8c6f 100644 --- a/app.go +++ b/app.go @@ -269,7 +269,7 @@ func Serve() { defer shutdown(app) schemaFileName := "schema.sql" - if app.cfg.Database.Type == "sqlite3" { + if app.cfg.Database.Type == driverSQLite { schemaFileName = "sqlite.sql" } @@ -370,7 +370,7 @@ func Serve() { app.formDecoder.RegisterConverter(sql.NullFloat64{}, converter.ConvertSQLNullFloat64) // Check database configuration - if app.cfg.Database.Type == "mysql" && (app.cfg.Database.User == "" || app.cfg.Database.Password == "") { + if app.cfg.Database.Type == driverMySQL && (app.cfg.Database.User == "" || app.cfg.Database.Password == "") { log.Error("Database user or password not set.") os.Exit(1) } @@ -471,10 +471,10 @@ func connectToDatabase(app *app) { var db *sql.DB var err error - if app.cfg.Database.Type == "mysql" { + if app.cfg.Database.Type == driverMySQL { db, err = sql.Open(app.cfg.Database.Type, fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=true&loc=%s", app.cfg.Database.User, app.cfg.Database.Password, app.cfg.Database.Host, app.cfg.Database.Port, app.cfg.Database.Database, url.QueryEscape(time.Local.String()))) db.SetMaxOpenConns(50) - } else if app.cfg.Database.Type == "sqlite3" { + } else if app.cfg.Database.Type == driverSQLite { if !SQLiteEnabled { log.Error("Invalid database type '%s'. Binary wasn't compiled with SQLite3 support.", app.cfg.Database.Type) os.Exit(1)