Skip to content

Commit

Permalink
Clarify HTTP RESTful service
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasher- committed Aug 29, 2017
1 parent 341302e commit 8a2c7c0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ func main() {
} else {
listenAddr := bot.config.Webserver.ListenAddress
log.Printf(
"HTTP Webserver support enabled. Listen URL: http://%s:%d/\n",
"HTTP RESTful Webserver support enabled. Listen URL: http://%s:%d/\n",
common.ExtractHost(listenAddr), common.ExtractPort(listenAddr),
)
router := NewRouter(bot.exchanges)
log.Fatal(http.ListenAndServe(listenAddr, router))
}
}
if !bot.config.Webserver.Enabled {
log.Println("HTTP Webserver support disabled.")
log.Println("HTTP RESTful Webserver support disabled.")
}

<-bot.shutdown
Expand Down
17 changes: 17 additions & 0 deletions restful_router.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"net/http"

"github.com/gorilla/mux"
Expand All @@ -15,6 +16,7 @@ func NewRouter(exchanges []exchange.IBotExchange) *mux.Router {
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
Expand All @@ -28,3 +30,18 @@ func NewRouter(exchanges []exchange.IBotExchange) *mux.Router {
}
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,
},
}

0 comments on commit 8a2c7c0

Please sign in to comment.