diff --git a/natsclient.go b/natsclient.go index 3c2f6d15..1893a8dd 100644 --- a/natsclient.go +++ b/natsclient.go @@ -27,6 +27,7 @@ import ( "encoding/json" "fmt" "log" + "net/url" "os" "os/signal" "strings" @@ -101,7 +102,7 @@ func NewNatsClient(url string) (NatsClient, error) { client.conn, err = nats.Connect(url) } - log.Printf("Connection established to %s (%s)", client.conn.ConnectedUrl(), client.conn.ConnectedServerId()) + log.Printf("Connection established to %s (%s)", removeURLCredentials(client.conn.ConnectedUrl()), client.conn.ConnectedServerId()) return client, nil } @@ -153,3 +154,11 @@ func (c *natsClient) Decode(msg *nats.Msg, vPtr interface{}) (err error) { } return } + +func removeURLCredentials(u string) string { + if u, err := url.Parse(u); err == nil && u.User != nil { + u.User = url.User("***") + return u.String() + } + return u +}