From b1d94cdabb326c8047bf2bdca3e1badc8059c395 Mon Sep 17 00:00:00 2001 From: hisham waleed karam Date: Sun, 14 Oct 2018 16:37:28 +0200 Subject: [PATCH] add dbType to DBIsAlive --- layer.go | 2 +- utils.go | 4 ++-- utils_test.go | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/layer.go b/layer.go index 7bf32d6..e45c0ef 100644 --- a/layer.go +++ b/layer.go @@ -56,7 +56,7 @@ func (manager *ManagerConfig) PublishGeoserverLayer(layer *GdalLayer) (ok bool, //LayerToPostgis add Layer to Postgis func (layer *GdalLayer) LayerToPostgis(targetSource *gdal.DataSource, manager *ManagerConfig, overwrite bool) (newLayer *GdalLayer, err error) { connStr := manager.Datastore.PostgresConnectionString() - dbErr := DBIsAlive(connStr) + dbErr := DBIsAlive("postgres", connStr) if dbErr != nil { err = dbErr return diff --git a/utils.go b/utils.go index e9b9f81..948bc28 100644 --- a/utils.go +++ b/utils.go @@ -73,8 +73,8 @@ func GetGISFiles(root string) ([]string, error) { } //DBIsAlive check if database alive -func DBIsAlive(connectionStr string) (err error) { - db, dbErr := sql.Open("postgres", connectionStr) +func DBIsAlive(dbType string, connectionStr string) (err error) { + db, dbErr := sql.Open(dbType, connectionStr) if dbErr != nil { err = dbErr return diff --git a/utils_test.go b/utils_test.go index 7900668..60bb682 100644 --- a/utils_test.go +++ b/utils_test.go @@ -27,9 +27,9 @@ func TestGetGISFiles(t *testing.T) { func TestDBIsAlive(t *testing.T) { manager, _ := FromConfig("./testdata/test_config.yml") connStr := manager.Datastore.PostgresConnectionString() - dbErr := DBIsAlive(connStr) + dbErr := DBIsAlive("postgres", connStr) assert.Nil(t, dbErr) - connStr = "xxxxx" - err := DBIsAlive(connStr) + connStr = "mysql://" + err := DBIsAlive("mysql", connStr) assert.NotNil(t, err) }