-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (32 loc) · 865 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
package main
import (
"log"
"net/http"
"github.com/joho/godotenv"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/stella-zone/celo-social-backend/database"
"github.com/stella-zone/celo-social-backend/routes"
)
func main() {
// Load the environment variables
err := godotenv.Load(".env")
if err != nil {
log.Fatalf("Error loading environment variables")
}
cors := handlers.CORS(
handlers.AllowedHeaders([]string{"content-type"}),
handlers.AllowedOrigins([]string{"*"}),
handlers.AllowCredentials(),
)
// Setup the database connection
database.SetupDatabaseConnection()
log.Printf("Starting at 8081")
router := setUpRouter()
log.Fatal(http.ListenAndServe("localhost:8081", cors(router)))
}
func setUpRouter() *mux.Router {
router := mux.NewRouter().StrictSlash(true)
routes.SetUpRoutes(router)
return router
}