~samwhited/xmpp

426fbfdcad2c2467e9e66decef1e893bc41fa547 — Sam Whited 5 years ago 5a3b4b1
Have JIDs implement net.Addr

I'm not entirely sure this makes sense; on the one hand, they are
addresses, on the other, the net package only supports a few protocols
and all of it's Dial methods take a string of the network type; making
up a new one probably breaks the point of having the Addr interface. I
suspect this was a bad design choice in the net package, as it rather
weakens the contract. Or maybe that's not the point of having a function
to return the network? I'm really not sure.

This should be considered experimental and may be reverted.
2 files changed, 9 insertions(+), 0 deletions(-)

M jid/jid.go
M jid/jid_test.go
M jid/jid.go => jid/jid.go +6 -0
@@ 143,6 143,12 @@ func (j *JID) Copy() *JID {
	}
}

// Satisfies the net.Addr interface by returning the name of the network for
// which the connection should be made.
func (j JID) Network() string {
	return "xmpp"
}

// String converts an JID to its string representation.
func (j JID) String() string {
	s := j.domainpart

M jid/jid_test.go => jid/jid_test.go +3 -0
@@ 7,6 7,7 @@ package jid
import (
	"encoding/xml"
	"fmt"
	"net"
	"testing"
)



@@ 16,6 17,8 @@ var _ fmt.Stringer = JID{}
var _ xml.MarshalerAttr = (*JID)(nil)
var _ xml.MarshalerAttr = JID{}
var _ xml.UnmarshalerAttr = (*JID)(nil)
var _ net.Addr = (*JID)(nil)
var _ net.Addr = JID{}

func TestValidJIDs(t *testing.T) {
	for _, jid := range []struct {