-
Notifications
You must be signed in to change notification settings - Fork 216
/
routes.go
55 lines (43 loc) · 1.83 KB
/
routes.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
46
47
48
49
50
51
52
53
54
55
// routes.go
package main
func initializeRoutes() {
// Use the setUserStatus middleware for every route to set a flag
// indicating whether the request was from an authenticated user or not
router.Use(setUserStatus())
// Handle the index route
router.GET("/", showIndexPage)
// Group user related routes together
userRoutes := router.Group("/u")
{
// Handle the GET requests at /u/login
// Show the login page
// Ensure that the user is not logged in by using the middleware
userRoutes.GET("/login", ensureNotLoggedIn(), showLoginPage)
// Handle POST requests at /u/login
// Ensure that the user is not logged in by using the middleware
userRoutes.POST("/login", ensureNotLoggedIn(), performLogin)
// Handle GET requests at /u/logout
// Ensure that the user is logged in by using the middleware
userRoutes.GET("/logout", ensureLoggedIn(), logout)
// Handle the GET requests at /u/register
// Show the registration page
// Ensure that the user is not logged in by using the middleware
userRoutes.GET("/register", ensureNotLoggedIn(), showRegistrationPage)
// Handle POST requests at /u/register
// Ensure that the user is not logged in by using the middleware
userRoutes.POST("/register", ensureNotLoggedIn(), register)
}
// Group article related routes together
articleRoutes := router.Group("/article")
{
// Handle GET requests at /article/view/some_article_id
articleRoutes.GET("/view/:article_id", getArticle)
// Handle the GET requests at /article/create
// Show the article creation page
// Ensure that the user is logged in by using the middleware
articleRoutes.GET("/create", ensureLoggedIn(), showArticleCreationPage)
// Handle POST requests at /article/create
// Ensure that the user is logged in by using the middleware
articleRoutes.POST("/create", ensureLoggedIn(), createArticle)
}
}