-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrouter.go
45 lines (38 loc) · 1.21 KB
/
router.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
43
44
45
package main
import (
"github.com/aybabtme/goblog/auth"
"github.com/aybabtme/goblog/ctlr"
"github.com/aybabtme/goblog/model"
"github.com/gorilla/mux"
"net/http"
)
type Router string
func (r Router) Start(port string, conn *model.DBConnection) error {
controllers := []ctlr.Controller{
ctlr.NewIndexController(),
ctlr.NewAuthorController(),
ctlr.NewAuthorListController(),
ctlr.NewUserController(),
ctlr.NewLabelController(),
ctlr.NewPostController(),
ctlr.NewPostComposeController(),
ctlr.NewPostSaveController(),
ctlr.NewPostUpdateController(),
ctlr.NewPostDestroyController(),
ctlr.NewPostCommentController(),
ctlr.NewPostEditController(),
ctlr.NewPostIdController()}
muxer := mux.NewRouter()
for _, ctlr := range controllers {
muxer.HandleFunc(ctlr.Path(), ctlr.Controller(conn))
}
// serve dynamic resources
http.Handle("/", muxer)
// serve static resources
http.Handle("/res/", http.StripPrefix("/res", http.FileServer(http.Dir("public/"))))
// For user authentication
http.HandleFunc("/authorize", auth.AuthorizeOauth)
http.HandleFunc("/oauth2callback", auth.GetHandleOAuth2Callback(conn))
http.HandleFunc("/logout", auth.Logout(conn))
return http.ListenAndServe(":"+port, nil)
}