From 8da21b1024293614104747bdf3964409b3a24b52 Mon Sep 17 00:00:00 2001 From: namhq1989 Date: Fri, 26 Aug 2022 15:17:25 +0700 Subject: [PATCH] fix return data in Connect function --- postgresql.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/postgresql.go b/postgresql.go index f4ad6b4..aafca37 100644 --- a/postgresql.go +++ b/postgresql.go @@ -24,7 +24,7 @@ type Config struct { } // Connect ... -func Connect(cfg Config, server string) *sql.DB { +func Connect(cfg Config, server string) (*sql.DB, error) { uri := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=%s", cfg.Host, cfg.Port, cfg.User, cfg.Password, cfg.DBName, cfg.SSLMode) @@ -41,7 +41,7 @@ func Connect(cfg Config, server string) *sql.DB { Message: err.Error(), Data: cfg, }) - panic(err) + return nil, err } // config @@ -66,5 +66,5 @@ func Connect(cfg Config, server string) *sql.DB { fmt.Printf("⚡️[postgres]: connected to %s:%d \n", cfg.Host, cfg.Port) - return db + return db, nil }