JID Full() vs String() and docs.
This commit is contained in:
parent
b908366544
commit
6da9c080d4
|
|
@ -5,12 +5,23 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
Jabber Identifier - uniquely identifies an individual entity in a XMPP/Jabber
|
||||||
|
network.
|
||||||
|
*/
|
||||||
type JID struct {
|
type JID struct {
|
||||||
|
// Local component e.g. the alice of alice@example.com/foo.
|
||||||
Local string
|
Local string
|
||||||
|
|
||||||
|
// Domain component, e.g. the example.com of alice@example.com/foo for a
|
||||||
|
// client or the whole JID of a component.
|
||||||
Domain string
|
Domain string
|
||||||
|
|
||||||
|
// Resource component, e.g. the foo of alice@example.com/foo.
|
||||||
Resource string
|
Resource string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the "bare" JID, i.e. no resource component.
|
||||||
func (jid JID) Bare() string {
|
func (jid JID) Bare() string {
|
||||||
if jid.Local == "" {
|
if jid.Local == "" {
|
||||||
return jid.Domain
|
return jid.Domain
|
||||||
|
|
@ -18,13 +29,20 @@ func (jid JID) Bare() string {
|
||||||
return fmt.Sprintf("%s@%s", jid.Local, jid.Domain)
|
return fmt.Sprintf("%s@%s", jid.Local, jid.Domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (jid JID) String() string {
|
// Return the full JID as a string.
|
||||||
|
func (jid JID) Full() string {
|
||||||
if jid.Resource == "" {
|
if jid.Resource == "" {
|
||||||
return jid.Bare()
|
return jid.Bare()
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s@%s/%s", jid.Local, jid.Domain, jid.Resource)
|
return fmt.Sprintf("%s@%s/%s", jid.Local, jid.Domain, jid.Resource)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return full JID as a string.
|
||||||
|
func (jid JID) String() string {
|
||||||
|
return jid.Full()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse a string into a JID structure.
|
||||||
func ParseJID(s string) (jid JID, err error) {
|
func ParseJID(s string) (jid JID, err error) {
|
||||||
|
|
||||||
if parts := strings.SplitN(s, "/", 2); len(parts) == 1 {
|
if parts := strings.SplitN(s, "/", 2); len(parts) == 1 {
|
||||||
|
|
@ -43,3 +61,5 @@ func ParseJID(s string) (jid JID, err error) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BUG(matt): ParseJID should fail for incorrectly formatted JIDs.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue