Made JID.Node a string rather than *string. This is more appropriate
authorChris Jones <chris@cjones.org>
Wed, 28 Dec 2011 13:32:11 -0700
changeset 25 7437d6eed227
parent 24 fff79efe06f6
child 26 4d0a369079ce
Made JID.Node a string rather than *string. This is more appropriate and idiomatic Go.
stream.go
structs.go
structs_test.go
--- a/stream.go	Wed Dec 28 13:28:45 2011 -0700
+++ b/stream.go	Wed Dec 28 13:32:11 2011 -0700
@@ -383,10 +383,10 @@
 	// Begin building the response. Username is
 	// user@domain or just domain.
 	var username string
-	if cl.Jid.Node == nil {
+	if cl.Jid.Node == "" {
 		username = cl.Jid.Domain
 	} else {
-		username = *cl.Jid.Node
+		username = cl.Jid.Node
 	}
 
 	// Generate our own nonce from random data.
--- a/structs.go	Wed Dec 28 13:28:45 2011 -0700
+++ b/structs.go	Wed Dec 28 13:32:11 2011 -0700
@@ -21,8 +21,7 @@
 // entities. It looks like node@domain/resource. Node and resource are
 // sometimes optional.
 type JID struct {
-	// BUG(cjyar) Make this not a pointer.
-	Node *string
+	Node string
 	Domain string
 	Resource string
 }
@@ -156,8 +155,8 @@
 
 func (jid *JID) String() string {
 	result := jid.Domain
-	if jid.Node != nil {
-		result = *jid.Node + "@" + result
+	if jid.Node != "" {
+		result = jid.Node + "@" + result
 	}
 	if jid.Resource != "" {
 		result = result + "/" + jid.Resource
@@ -171,11 +170,7 @@
 	if parts == nil {
 		return false
 	}
-	if parts[2] == "" {
-		jid.Node = nil
-	} else {
-		jid.Node = &parts[2]
-	}
+	jid.Node = parts[2]
 	jid.Domain = parts[3]
 	jid.Resource = parts[5]
 	return true
--- a/structs_test.go	Wed Dec 28 13:28:45 2011 -0700
+++ b/structs_test.go	Wed Dec 28 13:32:11 2011 -0700
@@ -23,7 +23,7 @@
 	if !jid.Set(str) {
 		t.Errorf("Set(%s) failed\n", str)
 	}
-	assertEquals(t, "user", *jid.Node)
+	assertEquals(t, "user", jid.Node)
 	assertEquals(t, "domain", jid.Domain)
 	assertEquals(t, "res", jid.Resource)
 	assertEquals(t, str, jid.String())
@@ -32,8 +32,8 @@
 	if !jid.Set(str) {
 		t.Errorf("Set(%s) failed\n", str)
 	}
-	if jid.Node != nil {
-		t.Errorf("Node: %v\n", *jid.Node)
+	if jid.Node != "" {
+		t.Errorf("Node: %v\n", jid.Node)
 	}
 	assertEquals(t, "domain.tld", jid.Domain)
 	if jid.Resource != "" {