forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestful_router.go
47 lines (41 loc) · 1.2 KB
/
restful_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
46
47
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
"github.com/thrasher-/gocryptotrader/exchanges"
)
// NewRouter takes in the exchange interfaces and returns a new multiplexor
// router
func NewRouter(exchanges []exchange.IBotExchange) *mux.Router {
router := mux.NewRouter().StrictSlash(true)
allRoutes := append(routes, ExchangeRoutes...)
allRoutes = append(allRoutes, ConfigRoutes...)
allRoutes = append(allRoutes, PortfolioRoutes...)
allRoutes = append(allRoutes, WalletRoutes...)
allRoutes = append(allRoutes, IndexRoute...)
for _, route := range allRoutes {
var handler http.Handler
handler = route.HandlerFunc
handler = Logger(handler, route.Name)
router.
Methods(route.Method).
Path(route.Pattern).
Name(route.Name).
Handler(handler)
}
return router
}
func getIndex(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "<html>GoCryptoTrader RESTful interface. For the web GUI, please visit the <a href=https://github.com/thrasher-/gocryptotrader/blob/master/web/README.md>web GUI readme.</a></html>")
w.WriteHeader(http.StatusOK)
}
// IndexRoute maps the index route to the getIndex function
var IndexRoute = Routes{
Route{
"",
"GET",
"/",
getIndex,
},
}