-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_route.go
98 lines (91 loc) · 2.05 KB
/
http_route.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"net/http"
"github.com/gorilla/mux"
)
type route struct {
Name string
Method []string
Pattern string
HandlerFunc http.HandlerFunc
}
type routeManager struct {
apiRoutes []route
webPageRoutes []route
pageHandler *pageHandler
apiHandler *apiHandler
Router *mux.Router
dCache dataStore
}
func newRouteManager(dCache dataStore) *routeManager {
rm := new(routeManager)
rm.pageHandler = newPageHandler(dCache)
rm.apiHandler = newAPIHandler(dCache)
rm.Router = rm.registerRoutes()
return rm
}
func (rm *routeManager) registerRoutes() *mux.Router {
router := mux.NewRouter().StrictSlash(true)
rm.routeMapping()
for _, route := range rm.webPageRoutes {
router.
Methods(route.Method...).
Path(route.Pattern).
Name(route.Name).
Handler(route.HandlerFunc)
}
router.PathPrefix("/assets/").Handler(http.StripPrefix("/assets/", http.FileServer(http.Dir("./templates/assets/"))))
return router
}
func (rm *routeManager) routeMapping() {
rm.webPageRoutes = []route{
{
"Login page",
[]string{"GET"},
"/",
rm.pageHandler.getLoginPage,
},
{
"Etsy login page",
[]string{"POST"},
"/authorize-etsy",
rm.pageHandler.redirectToEtsy,
},
{
"Callback from etsy after successful authorization",
[]string{"GET"},
"/callback-etsy",
rm.pageHandler.etsyAuthorizationCallback,
},
{
"Redirection to trello for authorizaton",
[]string{"POST"},
"/authorize-trello",
rm.pageHandler.redirectToTrello,
},
{
"Callback from trello after successful authorization",
[]string{"GET"},
"/callback-trello",
rm.pageHandler.trelloAuthorizationCallback,
},
{
"Show details page after successful login",
[]string{"GET"},
"/details",
rm.pageHandler.showDetails,
},
{
"Get a list of boards associated with trello",
[]string{"GET"},
"/api/trello-boards/{boardId}/lists",
rm.apiHandler.getBordLists,
},
{
"Save board and list and link it to etsy",
[]string{"POST"},
"/api/user-info",
rm.apiHandler.saveBoardAndList,
},
}
}