Skip to content

Commit

Permalink
Merge pull request thrasher-corp#20 from cornelk/master
Browse files Browse the repository at this point in the history
go fmt and printf fixes
  • Loading branch information
thrasher- authored Feb 2, 2017
2 parents 7ba0cda + fbc33a0 commit 7610766
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 36 deletions.
2 changes: 1 addition & 1 deletion bitfinexwebsocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
4 changes: 2 additions & 2 deletions bitstampwebsocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions btccwebsocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
8 changes: 4 additions & 4 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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))
}
}

Expand All @@ -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))
}
}
4 changes: 2 additions & 2 deletions huobiwebsocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
2 changes: 1 addition & 1 deletion okcoinwebsocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
17 changes: 8 additions & 9 deletions orders.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package main

const (
Expand All @@ -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)
Expand All @@ -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:]...)
Expand Down Expand Up @@ -61,4 +60,4 @@ func GetOrderByOrderID(orderID int) (*Order, bool) {
}
}
return nil, false
}
}
30 changes: 15 additions & 15 deletions restfulLogger.go
Original file line number Diff line number Diff line change
@@ -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),
)
})
}

0 comments on commit 7610766

Please sign in to comment.