From d2d0c871541c2ebcaf1142a6641190b49fbb8362 Mon Sep 17 00:00:00 2001 From: Jonathan McCall Date: Wed, 4 Apr 2018 10:57:58 -0400 Subject: [PATCH] Make periodic reconnection optional, defaults to false --- client.go | 10 +++++++--- client_test.go | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index bea30c9..b158efb 100644 --- a/client.go +++ b/client.go @@ -46,6 +46,7 @@ type StatsdClient struct { eventStringTpl string Logger Logger conn_type string + reconnect bool reconnect_ticker *time.Ticker } @@ -58,14 +59,17 @@ func NewStatsdClient(addr string, prefix string) *StatsdClient { prefix: prefix, Logger: log.New(os.Stdout, "[StatsdClient] ", log.Ldate|log.Ltime), eventStringTpl: "%s%s:%s", + reconnect: false, reconnect_ticker: time.NewTicker(30 * time.Second), } go func() { for range client.reconnect_ticker.C { - err := client.Reconnect() - if err != nil { - fmt.Println(err) + if client.reconnect { + err := client.Reconnect() + if err != nil { + fmt.Println(err) + } } } }() diff --git a/client_test.go b/client_test.go index 57c0438..12b4039 100644 --- a/client_test.go +++ b/client_test.go @@ -133,6 +133,7 @@ func TestReconnecting(t *testing.T) { prefix := "test." client := NewStatsdClient(udpAddr.String(), prefix) + client.reconnect = true client.reconnect_ticker = time.NewTicker(10 * time.Millisecond) ch := make(chan string, 0)