mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-21 18:12:00 -08:00
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package stanza
|
|
|
|
import (
|
|
"encoding/xml"
|
|
)
|
|
|
|
type builder struct{ lang string }
|
|
|
|
// NewBuilder create a builder structure. It act as an interface for packet generation.
|
|
// The goal is to work well with code completion to more easily.
|
|
//
|
|
// Using the builder to format and create packets is optional. You can always prepare
|
|
// your packet dealing with the struct manually and initializing them with the right values.
|
|
func NewBuilder() *builder {
|
|
return &builder{}
|
|
}
|
|
|
|
// Set default language
|
|
func (b *builder) Lang(lang string) *builder {
|
|
b.lang = lang
|
|
return b
|
|
}
|
|
|
|
func (b *builder) IQ(a Attrs) IQ {
|
|
return IQ{
|
|
XMLName: xml.Name{Local: "iq"},
|
|
Attrs: a,
|
|
}
|
|
}
|
|
|
|
func (b *builder) Message(a Attrs) Message {
|
|
return Message{
|
|
XMLName: xml.Name{Local: "message"},
|
|
Attrs: a,
|
|
}
|
|
}
|
|
|
|
func (b *builder) Presence(a Attrs) Presence {
|
|
return Presence{
|
|
XMLName: xml.Name{Local: "presence"},
|
|
Attrs: a,
|
|
}
|
|
}
|
|
|
|
// ======================================================================================
|
|
// IQ payloads
|
|
|
|
// DiscoInfo builds a default DiscoInfo payload
|
|
func (*builder) DiscoInfo() *DiscoInfo {
|
|
d := DiscoInfo{
|
|
XMLName: xml.Name{
|
|
Space: NSDiscoInfo,
|
|
Local: "query",
|
|
},
|
|
}
|
|
return &d
|
|
}
|
|
|
|
// Identity builds a identity struct for use in Disco
|
|
func (*builder) Identity(name, category, typ string) *Identity {
|
|
return &Identity{}
|
|
}
|