Skip to content

Changed the fmt.Print to Debug level logging in ticker.go #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/gocarina/gocsv v0.0.0-20180809181117-b8c38cb1ba36
github.com/google/go-querystring v1.0.0
github.com/gorilla/websocket v1.4.2
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stretchr/testify v1.7.0
gopkg.in/jarcoal/httpmock.v1 v1.0.0-20180719183105-8007e27cdb32
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gocarina/gocsv v0.0.0-20180809181117-b8c38cb1ba36 h1:IlBbYij72r3CoD3fKTbP5jD0NJjrvemKsaxkW/QUdGE=
github.com/gocarina/gocsv v0.0.0-20180809181117-b8c38cb1ba36/go.mod h1:/oj50ZdPq/cUjA02lMZhijk5kR31SEydKyqah1OgBuo=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
Expand All @@ -8,9 +10,13 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/jarcoal/httpmock.v1 v1.0.0-20180719183105-8007e27cdb32 h1:30DLrQoRqdUHslVMzxuKUnY4GKJGk1/FJtKy3yx4TKE=
Expand Down
15 changes: 8 additions & 7 deletions ticker/ticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"encoding/binary"
"encoding/json"
"fmt"
"log"
"math"
"net/url"
"os"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -39,20 +41,21 @@ type Ticker struct {

subscribedTokens map[uint32]Mode

cancel context.CancelFunc
cancel context.CancelFunc
debugLog *log.Logger
}

// atomicTime is wrapper over time.Time to safely access
// an updating timestamp concurrently.
type atomicTime struct {
v atomic.Value
}

// Get returns the current timestamp.
func (b *atomicTime) Get() time.Time {
return b.v.Load().(time.Time)
}

// Set sets the current timestamp.
func (b *atomicTime) Set(value time.Time) {
b.v.Store(value)
Expand Down Expand Up @@ -165,6 +168,7 @@ func New(apiKey string, accessToken string) *Ticker {
reconnectMaxRetries: defaultReconnectMaxAttempts,
connectTimeout: defaultConnectTimeout,
subscribedTokens: map[uint32]Mode{},
debugLog: log.New(os.Stdout, "DEBUG : ", log.Ldate|log.Ltime|log.Lshortfile),
}

return ticker
Expand Down Expand Up @@ -356,7 +360,6 @@ func (t *Ticker) handleClose(code int, reason string) error {
return nil
}


// Trigger callback methods
func (t *Ticker) triggerError(err error) {
if t.callbacks.onError != nil {
Expand Down Expand Up @@ -388,7 +391,6 @@ func (t *Ticker) triggerNoReconnect(attempt int) {
}
}


func (t *Ticker) triggerMessage(messageType int, message []byte) {
if t.callbacks.onMessage != nil {
t.callbacks.onMessage(messageType, message)
Expand Down Expand Up @@ -568,7 +570,7 @@ func (t *Ticker) Resubscribe() error {
}
}

fmt.Println("Subscribe again: ", tokens, t.subscribedTokens)
t.debugLog.Println("Subscribe again: ", tokens, t.subscribedTokens)

// Subscribe to tokens
if len(tokens) > 0 {
Expand Down Expand Up @@ -776,4 +778,3 @@ func convertPrice(seg uint32, val float64) float64 {
return val / 100.0
}
}