create sevrer
This commit is contained in:
parent
088e83d6e6
commit
08f8693e8d
4 changed files with 112 additions and 0 deletions
19
db/db.go
Normal file
19
db/db.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue