Merge pull request #20 from cornelk/master

go fmt and printf fixes
This commit is contained in:
thrasher
2017-02-02 12:48:17 +11:00
committed by GitHub
8 changed files with 35 additions and 36 deletions

View File

@@ -246,7 +246,7 @@ func (b *Bitfinex) WebsocketClient() {
chanInfo, ok := b.WebsocketSubdChannels[chanID]
if !ok {
log.Println("Unable to locate chanID: %d", chanID)
log.Printf("Unable to locate chanID: %d\n", chanID)
} else {
if len(chanData) == 2 {
if reflect.TypeOf(chanData[1]).String() == "string" {

View File

@@ -39,12 +39,12 @@ func (b *Bitstamp) PusherClient() {
dataChannelTrade, err := pusherClient.Bind("data")
if err != nil {
log.Printf("%s Websocket Bind error: ", b.GetName(), err)
log.Printf("%s Websocket Bind error: %s\n", b.GetName(), err)
continue
}
tradeChannelTrade, err := pusherClient.Bind("trade")
if err != nil {
log.Printf("%s Websocket Bind error: ", b.GetName(), err)
log.Printf("%s Websocket Bind error: %s\n", b.GetName(), err)
continue
}

View File

@@ -141,9 +141,9 @@ func (b *BTCC) WebsocketClient() {
for b.Enabled && b.Websocket {
err := socketio.ConnectToSocket(BTCC_SOCKETIO_ADDRESS, BTCCSocket)
if err != nil {
log.Printf("%s Unable to connect to Websocket. Err: %s\n", err)
log.Printf("%s Unable to connect to Websocket. Err: %s\n", b.GetName(), err)
continue
}
log.Printf("%s Disconnected from Websocket.")
log.Printf("%s Disconnected from Websocket.\n", b.GetName())
}
}

View File

@@ -124,7 +124,7 @@ func TestStringContains(t *testing.T) {
expectedOutput := true
actualResult := StringContains(originalInput, originalInputSubstring)
if actualResult != expectedOutput {
t.Error(fmt.Sprintf("Test failed. Expected '%s'. Actual '%s'", expectedOutput, actualResult))
t.Error(fmt.Sprintf("Test failed. Expected '%t'. Actual '%t'", expectedOutput, actualResult))
}
}
@@ -213,14 +213,14 @@ func TestExtractHost(t *testing.T) {
expectedOutput := "localhost"
actualResult := ExtractHost(address)
if expectedOutput != actualResult {
t.Error(fmt.Sprintf("Test failed. Expected '%f'. Actual '%f'.", expectedOutput, actualResult))
t.Error(fmt.Sprintf("Test failed. Expected '%s'. Actual '%s'.", 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))
t.Error(fmt.Sprintf("Test failed. Expected '%s'. Actual '%s'.", expectedOutput, actualResult))
}
}
@@ -230,6 +230,6 @@ func TestExtractPort(t *testing.T) {
expectedOutput := 1337
actualResult := ExtractPort(address)
if expectedOutput != actualResult {
t.Error(fmt.Sprintf("Test failed. Expected '%f'. Actual '%f'.", expectedOutput, actualResult))
t.Error(fmt.Sprintf("Test failed. Expected '%d'. Actual '%d'.", expectedOutput, actualResult))
}
}

View File

@@ -211,9 +211,9 @@ func (h *HUOBI) WebsocketClient() {
for h.Enabled && h.Websocket {
err := socketio.ConnectToSocket(HUOBI_SOCKETIO_ADDRESS, HuobiSocket)
if err != nil {
log.Printf("%s Unable to connect to Websocket. Err: %s\n", err)
log.Printf("%s Unable to connect to Websocket. Err: %s\n", h.GetName(), err)
continue
}
log.Printf("%s Disconnected from Websocket.")
log.Printf("%s Disconnected from Websocket.\n", h.GetName())
}
}

View File

@@ -482,7 +482,7 @@ func (o *OKCoin) WebsocketClient() {
if success != "true" && success != nil {
errorCodeStr, ok := errorcode.(string)
if !ok {
log.Printf("%s Websocket: Unable to convert errorcode to string.\n", o.GetName)
log.Printf("%s Websocket: Unable to convert errorcode to string.\n", o.GetName())
log.Printf("%s Websocket: channel %s error code: %s.\n", o.GetName(), channelStr, errorcode)
} else {
log.Printf("%s Websocket: channel %s error: %s.\n", o.GetName(), channelStr, o.WebsocketErrors[errorCodeStr])

View File

@@ -1,4 +1,3 @@
package main
const (
@@ -9,16 +8,16 @@ const (
var Orders []*Order
type Order struct {
OrderID int
OrderID int
Exchange string
Type int
Amount float64
Price float64
Type int
Amount float64
Price float64
}
func NewOrder(Exchange string, amount, price float64) (int) {
func NewOrder(Exchange string, amount, price float64) int {
order := &Order{}
if (len(Orders) == 0) {
if len(Orders) == 0 {
order.OrderID = 0
} else {
order.OrderID = len(Orders)
@@ -31,7 +30,7 @@ func NewOrder(Exchange string, amount, price float64) (int) {
return order.OrderID
}
func DeleteOrder(orderID int) (bool) {
func DeleteOrder(orderID int) bool {
for i := range Orders {
if Orders[i].OrderID == orderID {
Orders = append(Orders[:i], Orders[i+1:]...)
@@ -61,4 +60,4 @@ func GetOrderByOrderID(orderID int) (*Order, bool) {
}
}
return nil, false
}
}

View File

@@ -1,23 +1,23 @@
package main
import (
"log"
"net/http"
"time"
"log"
"net/http"
"time"
)
func Logger(inner http.Handler, name string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
inner.ServeHTTP(w, r)
inner.ServeHTTP(w, r)
log.Printf(
"%s\t%s\t%s\t%s",
r.Method,
r.RequestURI,
name,
time.Since(start),
)
})
}
log.Printf(
"%s\t%s\t%s\t%s",
r.Method,
r.RequestURI,
name,
time.Since(start),
)
})
}