mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-12-17 14:02:04 -08:00
Add basic builder support
This commit is contained in:
parent
cb9016693c
commit
1dacc663d3
62
stanza/builder.go
Normal file
62
stanza/builder.go
Normal file
@ -0,0 +1,62 @@
|
||||
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{}
|
||||
}
|
Loading…
Reference in New Issue
Block a user