You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the NATS connection status is a constant backed by an iota, this means consumers wishing to write out the connection status as a human readable format (such as logs) requires something like this:
It would be great if the client library could provide such a functionality to get a human readable version of the connection status.
Proposed Change:
My initial thoughts were perhaps a pointer function such as func (nc *Conn) StatusText() string that returns the uppercase string of the connection status.
Alternative Approaches
Whilst a slightly larger, breaking change - another option is to make it a type like so, which could then implement the Stringer interface.
func (s Status) String() string {
switch s {
case DISCONNECTED:
return "DISCONNECTED"
case CONNECTED:
return "CONNECTED"
case CLOSED:
return "CLOSED"
case RECONNECTING:
return "RECONNECTING"
case CONNECTING:
return "CONNECTING"
case DRAINING_SUBS:
return "DRAINING_SUBS"
case DRAINING_PUBS:
return "DRAINING_PUBS"
}
return "unknown status"
}
which seem to work:
nc, err := nats.Connect(...)
..
st := nc.Status()
fmt.Printf("status=%s\n", st)
Feature Request
Currently the NATS connection status is a constant backed by an iota, this means consumers wishing to write out the connection status as a human readable format (such as logs) requires something like this:
It would be great if the client library could provide such a functionality to get a human readable version of the connection status.
Proposed Change:
My initial thoughts were perhaps a pointer function such as
func (nc *Conn) StatusText() string
that returns the uppercase string of the connection status.Alternative Approaches
Whilst a slightly larger, breaking change - another option is to make it a type like so, which could then implement the
Stringer
interface.The text was updated successfully, but these errors were encountered: