-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (37 loc) · 1.19 KB
/
main.go
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
38
39
40
41
42
43
44
45
46
47
package main
import (
"database/sql"
"fmt"
"os"
"github.com/joho/godotenv"
_ "github.com/lib/pq"
"github.com/wisedevguy/fp-sanbercode-golang-batch-41-v2/database"
"github.com/wisedevguy/fp-sanbercode-golang-batch-41-v2/routers"
)
var (
DB *sql.DB
err error
)
func main() {
//err = godotenv.Load("config/local.env")
err = godotenv.Load("config/deploy.env")
if err != nil {
fmt.Println("FAILED load file environment")
} else {
fmt.Println("SUCCESS read file environment")
}
//psqlInfo := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable", os.Getenv("DB_HOST"), os.Getenv("DB_PORT"), os.Getenv("DB_USER"), os.Getenv("DB_PASSWORD"), os.Getenv("DB_NAME"))
psqlInfo := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable", os.Getenv("PGHOST"), os.Getenv("PGPORT"), os.Getenv("PGUSER"), os.Getenv("PGPASSWORD"), os.Getenv("PGDATABASE"))
DB, err = sql.Open("postgres", psqlInfo)
err = DB.Ping()
if err != nil {
fmt.Println("DB connection FAILED")
panic(err)
} else {
fmt.Println("DB connection SUCCESS")
}
database.DbMigrate(DB)
defer DB.Close()
//routers.StartServer().Run(":8080")
routers.StartServer().Run(":" + os.Getenv("PORT"))
}