You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-xmpp/jid.go

35 lines
521 B

package xmpp // import "fluux.io/xmpp"
import (
"errors"
"strings"
)
type Jid struct {
username string
domain string
resource string
}
func NewJid(sjid string) (jid *Jid, err error) {
s1 := strings.Split(sjid, "@")
if len(s1) != 2 {
err = errors.New("invalid JID: " + sjid)
return
}
jid = new(Jid)
jid.username = s1[0]
s2 := strings.Split(s1[1], "/")
if len(s2) > 2 {
err = errors.New("invalid JID: " + sjid)
return
}
jid.domain = s2[0]
if len(s2) == 2 {
jid.resource = s2[1]
}
return
}