goblog/db/db.go

19 lines
427 B
Go
Raw Normal View History

2024-12-07 22:45:46 +00:00
package db
import (
"database/sql"
_ "github.com/lib/pq"
"log"
)
// Replace the "connStr" string with your DB connection username and password.
func ConnectDB() (*sql.DB, error) {
connStr := "user=username password=password123 dbname=cooldatabase sslmode=disable"
db, err := sql.Open("postgres", connStr)
if err != nil {
log.Fatalf("Failed to connect to the database: %v", err)
return nil, err
}
return db, nil
}