-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (33 loc) · 870 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
// package Main - BestEver prototype
package main
import (
"flag"
"log"
"net/http"
"os"
"github.com/jsadwith/BestEver/database"
"github.com/jsadwith/BestEver/models"
"github.com/jsadwith/BestEver/routes"
)
var (
port = flag.String(
"PORT",
os.Getenv("PORT"),
"",
)
)
func main() {
// Register routes, ensuring trailing slashes redirect to route - /route/ -> /route
router := router.NewRouter()
err := database.Connect()
if err != nil {
log.Fatalf("Error connecting to Postgres: %s", err)
}
// Table creation and auto migrate
database.Client.CreateTable(&models.Category{})
database.Client.CreateTable(&models.Item{})
database.Client.CreateTable(&models.User{})
database.Client.AutoMigrate(&models.Category{}, &models.Item{}, &models.User{})
log.Printf("Serving on port " + *port)
log.Fatal(http.ListenAndServe(":"+*port, router))
}