func connectDB(host string, dbname string, username string, password string, sslmode string, port int) *sqlx.DB { // TODO This could be rewritten in a nicer way dbURL := connectionString(host, dbname, username, password, sslmode, port) db := sqlx.MustOpen("postgres", dbURL) // we do a manual ping because MustConnect raise a panic err := db.Ping() if err != nil { if len(password) > 0 || !strings.Contains(err.Error(), "password authentication failed") { log.Fatal(err) } pwd := "" fmt.Print("Enter Password: "******"postgres", dbURL) err := db.Ping() if err != nil { log.Fatal(err) } } return db }
func connectDB(dbURL string) *sqlx.DB { db := sqlx.MustOpen("postgres", dbURL) return db }