mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Display verbose listen address for HTTP server.
This commit is contained in:
14
common.go
14
common.go
@@ -17,6 +17,7 @@ import (
|
||||
"math"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -274,3 +275,16 @@ func EncodeURLValues(url string, values url.Values) string {
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
func ExtractHost(address string) string {
|
||||
host := SplitStrings(address, ":")[0]
|
||||
if host == "" {
|
||||
return "localhost"
|
||||
}
|
||||
return host
|
||||
}
|
||||
func ExtractPort(host string) int {
|
||||
portStr := SplitStrings(host, ":")[1]
|
||||
port, _ := strconv.Atoi(portStr)
|
||||
return port
|
||||
}
|
||||
|
||||
@@ -206,3 +206,30 @@ func TestCalculateNetProfit(t *testing.T) {
|
||||
t.Error(fmt.Sprintf("Test failed. Expected '%f'. Actual '%f'.", expectedOutput, actualResult))
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractHost(t *testing.T) {
|
||||
t.Parallel()
|
||||
address := "localhost:1337"
|
||||
expectedOutput := "localhost"
|
||||
actualResult := ExtractHost(address)
|
||||
if expectedOutput != actualResult {
|
||||
t.Error(fmt.Sprintf("Test failed. Expected '%f'. Actual '%f'.", expectedOutput, actualResult))
|
||||
}
|
||||
|
||||
address = "192.168.1.100:1337"
|
||||
expectedOutput = "192.168.1.100"
|
||||
actualResult = ExtractHost(address)
|
||||
if expectedOutput != actualResult {
|
||||
t.Error(fmt.Sprintf("Test failed. Expected '%f'. Actual '%f'.", expectedOutput, actualResult))
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractPort(t *testing.T) {
|
||||
t.Parallel()
|
||||
address := "localhost:1337"
|
||||
expectedOutput := 1337
|
||||
actualResult := ExtractPort(address)
|
||||
if expectedOutput != actualResult {
|
||||
t.Error(fmt.Sprintf("Test failed. Expected '%f'. Actual '%f'.", expectedOutput, actualResult))
|
||||
}
|
||||
}
|
||||
|
||||
5
main.go
5
main.go
@@ -138,9 +138,10 @@ func main() {
|
||||
log.Println(err) // non fatal event
|
||||
//bot.config.Webserver.Enabled = false
|
||||
} else {
|
||||
log.Println("HTTP Webserver support enabled.")
|
||||
listenAddr := bot.config.Webserver.ListenAddress
|
||||
log.Printf("HTTP Webserver support enabled. Listen URL: http://%s:%d/\n", ExtractHost(listenAddr), ExtractPort(listenAddr))
|
||||
router := NewRouter(bot.exchanges)
|
||||
log.Fatal(http.ListenAndServe(bot.config.Webserver.ListenAddress, router))
|
||||
log.Fatal(http.ListenAndServe(listenAddr, router))
|
||||
}
|
||||
}
|
||||
if !bot.config.Webserver.Enabled {
|
||||
|
||||
Reference in New Issue
Block a user