Skip to content

Commit

Permalink
Interface compatibility with *tls.Conn
Browse files Browse the repository at this point in the history
In order to use struct embedding and reduce boilerplate for functions
that take interfaces that return tls.ConnectionState, use the same
interface as the net/tls package.
  • Loading branch information
Sean Treadway committed Dec 5, 2016
1 parent 9bf0a87 commit b832186
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions connection.go
Expand Up @@ -235,8 +235,10 @@ func (me *Connection) LocalAddr() net.Addr {
return &net.TCPAddr{}
}

// TLSConnectionState returns basic TLS details of the underlying transport.
func (me *Connection) TLSConnectionState() tls.ConnectionState {
// ConnectionState returns basic TLS details of the underlying transport.
// Returns a zero value when the underlying connection does not implement
// ConnectionState() tls.ConnectionState.
func (me *Connection) ConnectionState() tls.ConnectionState {
if c, ok := me.conn.(interface {
ConnectionState() tls.ConnectionState
}); ok {
Expand Down
6 changes: 3 additions & 3 deletions tls_test.go
Expand Up @@ -4,11 +4,12 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"github.com/streadway/amqp"
"io"
"net"
"testing"
"time"

"github.com/streadway/amqp"
)

type tlsServer struct {
Expand Down Expand Up @@ -94,8 +95,7 @@ func TestTLSHandshake(t *testing.T) {
}
}

st := c.TLSConnectionState()
if !st.HandshakeComplete {
if st := c.ConnectionState(); !st.HandshakeComplete {
t.Errorf("TLS handshake failed, TLS connection state: %+v", st)
}
}
Expand Down

0 comments on commit b832186

Please sign in to comment.