-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
47 lines (39 loc) · 846 Bytes
/
main.go
File metadata and controls
47 lines (39 loc) · 846 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
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/joho/godotenv"
"github.com/ndv6/tsaving/api"
"github.com/ndv6/tsaving/database"
"github.com/ndv6/tsaving/tokens"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
port := os.Getenv("PORT")
if port == "" {
log.Fatal("$PORT must be set")
}
jwtSecret := os.Getenv("JWT_SECRET")
if jwtSecret == "" {
log.Fatal("$JWT_SECRET must be set")
}
jwt := tokens.New([]byte(jwtSecret))
dbUri := os.Getenv("DATABASE_URL")
if dbUri == "" {
log.Fatal("$DATABASE_URL must be set")
}
db, err := database.DatabaseConnect(dbUri)
if err != nil {
log.Fatal(err)
}
fmt.Println("Server is now accepting request at :" + port)
err = http.ListenAndServe(":"+port, api.Router(jwt, db))
if err != nil {
log.Fatal(err)
}
}