-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
34 lines (27 loc) · 778 Bytes
/
main.go
File metadata and controls
34 lines (27 loc) · 778 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
package main
import (
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/subosito/gotenv"
"log"
"net/http"
"rest/database"
"rest/routes"
)
func main() {
router := initialSetupAndGetRouter()
log.Println("Server started at port 8000...")
log.Fatal(http.ListenAndServe(":8000", handlers.CORS(
handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "Authorization"}),
handlers.AllowedMethods([]string{"GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS"}),
handlers.AllowedOrigins([]string{"*"}))(router)))
}
func initialSetupAndGetRouter() *mux.Router {
err := gotenv.Load()
if err != nil {
log.Fatal("Could not load env vars, exiting.")
}
database.CreateTablesAndPrePopulate()
router := routes.GetRouter()
return router
}