mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-21 10:02:00 -08:00
5eae7f4ef7
The URL will be more permanent as this is a place we dedicate as short URL for our go projects.
35 lines
522 B
Go
35 lines
522 B
Go
package xmpp // import "gosrc.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: " + sjidd)
|
|
return
|
|
}
|
|
jid.domain = s2[0]
|
|
if len(s2) == 2 {
|
|
jid.resource = s2[1]
|
|
}
|
|
|
|
return
|
|
}
|