-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.go
More file actions
37 lines (31 loc) · 740 Bytes
/
database.go
File metadata and controls
37 lines (31 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"database/sql"
"fmt"
"log"
"os"
"strconv"
_ "github.com/lib/pq"
)
var (
host = os.Getenv("DB_HOST")
port,_ = strconv.Atoi(os.Getenv("DB_PORT"))
user = os.Getenv("POSTGRES_USER")
password = os.Getenv("POSTGRES_PASSWORD")
dbname = os.Getenv("POSTGRES_DB")
)
// const (
// host = "localhost"
// port = 5432
// user = "planner_db"
// password = "posty_passy"
// dbname = "planner_db"
// )
var connectionString = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", host, port, user, password, dbname)
func getDB() (*sql.DB, error) {
db, err := sql.Open("postgres", connectionString)
if err != nil {
log.Fatal(err)
}
return db, err
}