-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
34 lines (31 loc) · 880 Bytes
/
main.go
File metadata and controls
34 lines (31 loc) · 880 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 (
"enchanted-codex/database"
"enchanted-codex/routes"
"enchanted-codex/services"
"log"
"net/http"
)
func LogMiddleware(mux *http.ServeMux) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s: %s", r.Method, r.URL.Path)
mux.ServeHTTP(w, r)
}
}
func main() {
db, err := database.GetDB()
if err != nil {
panic(err)
}
teamService, questionService, answerService := services.NewTeamServicxe(db), services.NewQuestionService(db), services.NewAnswerService(db)
mux := new(http.ServeMux)
viewRouter := routes.NewViewRouter(mux, teamService, questionService, answerService)
viewRouter.Use()
apiRouter := routes.NewAPIRoutes(mux, answerService, teamService)
apiRouter.Use()
log.Println("Server running on port 4000")
err = http.ListenAndServe(":4000", LogMiddleware(mux))
if err != nil {
panic(err)
}
}