-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (47 loc) · 1.17 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
48
49
50
51
52
53
54
55
56
package main
import (
"log"
"os"
"os/signal"
"github.com/joho/godotenv"
"github.com/michaeltintiuc/shackle-api/pkg/app"
"github.com/michaeltintiuc/shackle-api/pkg/session"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
port := getEnv("PORT", "8080")
dbInfo := app.DbInfo{
Host: os.Getenv("DB_HOST"),
Port: os.Getenv("DB_PORT"),
User: os.Getenv("DB_USER"),
Pass: os.Getenv("DB_PASS"),
Name: os.Getenv("DB_NAME"),
}
sessionInfo := session.SessionInfo{
AuthKey: []byte(os.Getenv("SESSION_AUTH_KEY")),
EncKey: []byte(os.Getenv("SESSION_ENC_KEY")),
Name: os.Getenv("SESSION_NAME"),
}
application, err := app.NewApp(port, dbInfo, sessionInfo)
if err != nil {
log.Fatalln(err)
}
go application.ListenAndServe()
// We'll accept graceful shutdowns when quit via SIGINT (Ctrl+C)
// SIGKILL, SIGQUIT or SIGTERM (Ctrl+/) will not be caught.
// Block until we receive our signal.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
application.Shutdown()
os.Exit(0)
}
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}