-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
47 lines (37 loc) · 879 Bytes
/
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 (
"log"
"os"
"github.com/joho/godotenv"
"github.com/midepeter/train-ticket/database/models"
"github.com/midepeter/train-ticket/database/postgres"
"github.com/midepeter/train-ticket/server"
)
func main() {
env := os.Getenv("ENV")
if env == "" {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file", err)
}
}
db, err := postgres.New(&postgres.Config{
Host: os.Getenv("DB_HOST"),
Port: os.Getenv("DB_PORT"),
Password: os.Getenv("DB_PASS"),
User: os.Getenv("DB_USER"),
DBName: os.Getenv("DB_NAME"),
SSLMode: os.Getenv("DB_SSLMODE"),
})
if err != nil {
log.Fatal("failed to connect to postgresql database", err)
}
err = postgres.SetupDatabase(db,
&models.Ticket{},
)
if err != nil {
log.Fatal("failed to setup tables", err)
}
r := server.StartServer(db)
r.Run(":8000")
}