diff --git a/doc.go b/doc.go index d157f91..1ff4514 100644 --- a/doc.go +++ b/doc.go @@ -3,11 +3,9 @@ Fluux XMPP is a Go XMPP library, focusing on simplicity, simple automation, and The goal is to make simple to write simple adhoc XMPP clients: -- For automation (like for example monitoring of an XMPP service), - -- For building connected "things" by plugging them on an XMPP server, - -- For writing simple chatbot to control a service or a thing. + - For automation (like for example monitoring of an XMPP service), + - For building connected "things" by plugging them on an XMPP server, + - For writing simple chatbots to control a service or a thing. */ package xmpp diff --git a/iq.go b/iq.go index be1e057..972f800 100644 --- a/iq.go +++ b/iq.go @@ -16,6 +16,9 @@ TODO support ability to put Raw payload // ============================================================================ // XMPP Errors +// Err is an XMPP stanza payload that is used to report error on message, +// presence or iq stanza. +// It is intended to be added in the payload of the erroneous stanza. type Err struct { XMLName xml.Name `xml:"error"` Code int `xml:"code,attr,omitempty"` @@ -250,6 +253,8 @@ type IQPayload interface { IsIQPayload() } +// Node is a generic structure to represent XML data. It is used to parse +// unreferenced or custom stanza payload. type Node struct { XMLName xml.Name Attrs []xml.Attr `xml:"-"` @@ -257,11 +262,15 @@ type Node struct { Nodes []Node `xml:",any"` } +// Attr represents generic XML attributes, as used on the generic XML Node +// representation. type Attr struct { K string V string } +// UnmarshalXML is a custom unmarshal function used by xml.Unmarshal to +// transform generic XML content into hierarchical Node structure. func (n *Node) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { // Assign "n.Attrs = start.Attr", without repeating xmlns in attributes: for _, attr := range start.Attr { @@ -274,6 +283,8 @@ func (n *Node) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { return d.DecodeElement((*node)(n), &start) } +// MarshalXML is a custom XML serializer used by xml.Marshal to serialize a +// Node structure to XML. func (n Node) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error) { start.Attr = n.Attrs start.Name = n.XMLName diff --git a/message_test.go b/message_test.go index fb1a557..1cb0adf 100644 --- a/message_test.go +++ b/message_test.go @@ -1,4 +1,4 @@ -package xmpp +package xmpp // import "fluux.io/xmpp" import ( "encoding/xml" diff --git a/presence_test.go b/presence_test.go index 06f381f..f5eb33c 100644 --- a/presence_test.go +++ b/presence_test.go @@ -1,4 +1,4 @@ -package xmpp +package xmpp // import "fluux.io/xmpp" import ( "encoding/xml"