|
@@ -3,13 +3,13 @@ package infrastructure
|
|
import (
|
|
import (
|
|
"database/sql"
|
|
"database/sql"
|
|
"github.com/spf13/viper"
|
|
"github.com/spf13/viper"
|
|
|
|
+
|
|
|
|
+ _ "github.com/go-sql-driver/mysql"
|
|
)
|
|
)
|
|
|
|
|
|
const exampleValidHTTPURL = "https://example.com"
|
|
const exampleValidHTTPURL = "https://example.com"
|
|
|
|
|
|
-/**
|
|
|
|
-DbDial is almost a proxy to sql.Open but guarantees that db will be nil if err is not nil.
|
|
|
|
- */
|
|
|
|
|
|
+// DbDial is almost a proxy to sql.Open but guarantees that db will be nil if err is not nil.
|
|
func DbDial(dbDriver, dbDsn string) (*sql.DB, error) {
|
|
func DbDial(dbDriver, dbDsn string) (*sql.DB, error) {
|
|
db, err := sql.Open(dbDriver, dbDsn)
|
|
db, err := sql.Open(dbDriver, dbDsn)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -18,9 +18,7 @@ func DbDial(dbDriver, dbDsn string) (*sql.DB, error) {
|
|
return db, nil
|
|
return db, nil
|
|
}
|
|
}
|
|
|
|
|
|
-/**
|
|
|
|
-ParseDbCred returns DB information from the supported configuration sources.
|
|
|
|
- */
|
|
|
|
|
|
+// ParseDbCred returns DB information from the supported configuration sources.
|
|
func ParseDbCred() (driver, dsn string) {
|
|
func ParseDbCred() (driver, dsn string) {
|
|
viper.SetDefault("database.driver", "mysql")
|
|
viper.SetDefault("database.driver", "mysql")
|
|
viper.SetDefault("database.dsn", "root:root@tcp(localhost:3306)/kurz")
|
|
viper.SetDefault("database.dsn", "root:root@tcp(localhost:3306)/kurz")
|
|
@@ -31,12 +29,9 @@ func ParseDbCred() (driver, dsn string) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-/**
|
|
|
|
-ParseDbCred returns Test DB information from the supported configuration sources.
|
|
|
|
- */
|
|
|
|
|
|
+// ParseDbCred returns Test DB information from the supported configuration sources.
|
|
func ParseTestDbCred() (driver, dsn string) {
|
|
func ParseTestDbCred() (driver, dsn string) {
|
|
viper.SetDefault("database.driver", "mysql")
|
|
viper.SetDefault("database.driver", "mysql")
|
|
- viper.SetDefault("database.dsn", "root:root@tcp(localhost:3306)/kurz")
|
|
|
|
viper.SetDefault("database.test_dsn", "root:root@tcp(localhost:3306)/kurz_test")
|
|
viper.SetDefault("database.test_dsn", "root:root@tcp(localhost:3306)/kurz_test")
|
|
|
|
|
|
driver = viper.Get("database.driver").(string)
|
|
driver = viper.Get("database.driver").(string)
|