From e9682915e464351139d668ca7a79ca5ccf1362fb Mon Sep 17 00:00:00 2001 From: Ivan Kozlovic Date: Tue, 5 May 2020 11:04:41 -0600 Subject: [PATCH] Change name of non-TLS option and clear go1.14 from go.mod Signed-off-by: Ivan Kozlovic --- go.mod | 2 -- nats.go | 64 +++++++++++++++++++++--------------------- test/reconnect_test.go | 4 +-- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index 508003a2b..bd7d44a21 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,5 @@ module github.com/nats-io/nats.go -go 1.14 - require ( github.com/nats-io/jwt v0.3.2 github.com/nats-io/nkeys v0.1.4 diff --git a/nats.go b/nats.go index 6189bb873..139581c44 100644 --- a/nats.go +++ b/nats.go @@ -45,21 +45,21 @@ import ( // Default Constants const ( - Version = "1.9.2" - DefaultURL = "nats://127.0.0.1:4222" - DefaultPort = 4222 - DefaultMaxReconnect = 60 - DefaultReconnectWait = 2 * time.Second - DefaultReconnectJitterNonTLS = 100 * time.Millisecond - DefaultReconnectJitterTLS = time.Second - DefaultTimeout = 2 * time.Second - DefaultPingInterval = 2 * time.Minute - DefaultMaxPingOut = 2 - DefaultMaxChanLen = 8192 // 8k - DefaultReconnectBufSize = 8 * 1024 * 1024 // 8MB - RequestChanLen = 8 - DefaultDrainTimeout = 30 * time.Second - LangString = "go" + Version = "1.9.2" + DefaultURL = "nats://127.0.0.1:4222" + DefaultPort = 4222 + DefaultMaxReconnect = 60 + DefaultReconnectWait = 2 * time.Second + DefaultReconnectJitter = 100 * time.Millisecond + DefaultReconnectJitterTLS = time.Second + DefaultTimeout = 2 * time.Second + DefaultPingInterval = 2 * time.Minute + DefaultMaxPingOut = 2 + DefaultMaxChanLen = 8192 // 8k + DefaultReconnectBufSize = 8 * 1024 * 1024 // 8MB + RequestChanLen = 8 + DefaultDrainTimeout = 30 * time.Second + LangString = "go" ) const ( @@ -129,17 +129,17 @@ func init() { // GetDefaultOptions returns default configuration options for the client. func GetDefaultOptions() Options { return Options{ - AllowReconnect: true, - MaxReconnect: DefaultMaxReconnect, - ReconnectWait: DefaultReconnectWait, - ReconnectJitterNonTLS: DefaultReconnectJitterNonTLS, - ReconnectJitterTLS: DefaultReconnectJitterTLS, - Timeout: DefaultTimeout, - PingInterval: DefaultPingInterval, - MaxPingsOut: DefaultMaxPingOut, - SubChanLen: DefaultMaxChanLen, - ReconnectBufSize: DefaultReconnectBufSize, - DrainTimeout: DefaultDrainTimeout, + AllowReconnect: true, + MaxReconnect: DefaultMaxReconnect, + ReconnectWait: DefaultReconnectWait, + ReconnectJitter: DefaultReconnectJitter, + ReconnectJitterTLS: DefaultReconnectJitterTLS, + Timeout: DefaultTimeout, + PingInterval: DefaultPingInterval, + MaxPingsOut: DefaultMaxPingOut, + SubChanLen: DefaultMaxChanLen, + ReconnectBufSize: DefaultReconnectBufSize, + DrainTimeout: DefaultDrainTimeout, } } @@ -276,10 +276,10 @@ type Options struct { // jitter to prevent all connections to attempt reconnecting at the same time. CustomReconnectDelayCB ReconnectDelayHandler - // ReconnectJitterNonTLS sets the upper bound for a random delay added to + // ReconnectJitter sets the upper bound for a random delay added to // ReconnectWait during a reconnect when no TLS is used. // Note that any jitter is capped with ReconnectJitterMax. - ReconnectJitterNonTLS time.Duration + ReconnectJitter time.Duration // ReconnectJitterTLS sets the upper bound for a random delay added to // ReconnectWait during a reconnect when TLS is used. @@ -702,10 +702,10 @@ func MaxReconnects(max int) Option { } // ReconnectJitter is an Option to set the upper bound of a random delay added ReconnectWait. -func ReconnectJitter(nonTLS, TLS time.Duration) Option { +func ReconnectJitter(jitter, jitterForTLS time.Duration) Option { return func(o *Options) error { - o.ReconnectJitterNonTLS = nonTLS - o.ReconnectJitterTLS = TLS + o.ReconnectJitter = jitter + o.ReconnectJitterTLS = jitterForTLS return nil } } @@ -1881,7 +1881,7 @@ func (nc *Conn) doReconnect(err error) { // TODO: since we sleep only after the whole list has been tried, we can't // rely on individual *srv to know if it is a TLS or non-TLS url. // We have to pick which type of jitter to use, for now, we use these hints: - jitter = nc.Opts.ReconnectJitterNonTLS + jitter = nc.Opts.ReconnectJitter if nc.Opts.Secure || nc.Opts.TLSConfig != nil { jitter = nc.Opts.ReconnectJitterTLS } diff --git a/test/reconnect_test.go b/test/reconnect_test.go index 61838ad54..579c8bc1e 100644 --- a/test/reconnect_test.go +++ b/test/reconnect_test.go @@ -41,8 +41,8 @@ func TestReconnectTotalTime(t *testing.T) { func TestDefaultReconnectJitter(t *testing.T) { opts := nats.GetDefaultOptions() - if opts.ReconnectJitterNonTLS != nats.DefaultReconnectJitterNonTLS { - t.Fatalf("Expected default jitter for non TLS to be %v, got %v", nats.DefaultReconnectJitterNonTLS, opts.ReconnectJitterNonTLS) + if opts.ReconnectJitter != nats.DefaultReconnectJitter { + t.Fatalf("Expected default jitter for non TLS to be %v, got %v", nats.DefaultReconnectJitter, opts.ReconnectJitter) } if opts.ReconnectJitterTLS != nats.DefaultReconnectJitterTLS { t.Fatalf("Expected default jitter for TLS to be %v, got %v", nats.DefaultReconnectJitterTLS, opts.ReconnectJitterTLS)