master
Andrey Ivanov 2020-12-10 04:26:03 -05:00 committed by Andrey Ivanov
parent ce6ab0345f
commit 4824e1c110
2 changed files with 7 additions and 4 deletions

View File

@ -18,4 +18,5 @@ linters:
- whitespace
- bodyclose
- wrapcheck
- exhaustivestruct
- exhaustivestruct
- staticcheck

View File

@ -91,12 +91,14 @@ func DialDSN(dsn string) (db *sql.DB, dbname string, err error) {
var driver string
switch {
case strings.HasPrefix(dsn, "postgres://") || strings.HasPrefix(dsn, "postgresql://") || strings.HasPrefix(dsn, "psql://"):
driver = "postgresql"
case strings.HasPrefix(dsn, "postgres://"):
driver = "postgres"
dsn = strings.TrimLeft(dsn, "postgres://")
case strings.HasPrefix(dsn, "mysql://"):
driver = "mysql"
dsn = strings.TrimLeft(dsn, "mysql://")
default:
driver = "postgresql"
return nil, "", fmt.Errorf("can't use unknown SQL dialect")
}
db, err = sql.Open(driver, dsn)