Clarify HTTP RESTful service

This commit is contained in:
Adrian Gallagher
2017-08-29 16:47:12 +10:00
parent 341302e91e
commit 8a2c7c03eb
2 changed files with 19 additions and 2 deletions

View File

@@ -195,7 +195,7 @@ 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)
@@ -203,7 +203,7 @@ func main() {
}
}
if !bot.config.Webserver.Enabled {
log.Println("HTTP Webserver support disabled.")
log.Println("HTTP RESTful Webserver support disabled.")
}
<-bot.shutdown

View File

@@ -1,6 +1,7 @@
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
@@ -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
@@ -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,
},
}