From c024098e1c78b193994316e7fd62c7b3108b2def Mon Sep 17 00:00:00 2001 From: "R.I.Pienaar" Date: Wed, 9 Mar 2022 17:51:14 +0100 Subject: [PATCH] adds a redacted version of ConnectedUrl() Signed-off-by: R.I.Pienaar --- nats.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nats.go b/nats.go index 7f2804fa3..83b39bafb 100644 --- a/nats.go +++ b/nats.go @@ -1803,6 +1803,21 @@ func (nc *Conn) ConnectedUrl() string { return nc.current.url.String() } +// ConnectedUrlRedacted reports the connected server's URL with passwords redacted +func (nc *Conn) ConnectedUrlRedacted() string { + if nc == nil { + return _EMPTY_ + } + + nc.mu.RLock() + defer nc.mu.RUnlock() + + if nc.status != CONNECTED { + return _EMPTY_ + } + return nc.current.url.Redacted() +} + // ConnectedAddr returns the connected server's IP func (nc *Conn) ConnectedAddr() string { if nc == nil {