Improve code documentation

This commit is contained in:
Mickael Remond 2018-01-25 17:04:19 +01:00
parent 7e50d313ea
commit ca148e5fe5
No known key found for this signature in database
GPG Key ID: E6F6045D79965AA3
4 changed files with 16 additions and 7 deletions

8
doc.go
View File

@ -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: The goal is to make simple to write simple adhoc XMPP clients:
- For automation (like for example monitoring of an XMPP service), - For automation (like for example monitoring of an XMPP service),
- For building connected "things" by plugging them on an XMPP server,
- For building connected "things" by plugging them on an XMPP server, - For writing simple chatbots to control a service or a thing.
- For writing simple chatbot to control a service or a thing.
*/ */
package xmpp package xmpp

11
iq.go
View File

@ -16,6 +16,9 @@ TODO support ability to put Raw payload
// ============================================================================ // ============================================================================
// XMPP Errors // 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 { type Err struct {
XMLName xml.Name `xml:"error"` XMLName xml.Name `xml:"error"`
Code int `xml:"code,attr,omitempty"` Code int `xml:"code,attr,omitempty"`
@ -250,6 +253,8 @@ type IQPayload interface {
IsIQPayload() IsIQPayload()
} }
// Node is a generic structure to represent XML data. It is used to parse
// unreferenced or custom stanza payload.
type Node struct { type Node struct {
XMLName xml.Name XMLName xml.Name
Attrs []xml.Attr `xml:"-"` Attrs []xml.Attr `xml:"-"`
@ -257,11 +262,15 @@ type Node struct {
Nodes []Node `xml:",any"` Nodes []Node `xml:",any"`
} }
// Attr represents generic XML attributes, as used on the generic XML Node
// representation.
type Attr struct { type Attr struct {
K string K string
V 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 { func (n *Node) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
// Assign "n.Attrs = start.Attr", without repeating xmlns in attributes: // Assign "n.Attrs = start.Attr", without repeating xmlns in attributes:
for _, attr := range start.Attr { 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) 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) { func (n Node) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error) {
start.Attr = n.Attrs start.Attr = n.Attrs
start.Name = n.XMLName start.Name = n.XMLName

View File

@ -1,4 +1,4 @@
package xmpp package xmpp // import "fluux.io/xmpp"
import ( import (
"encoding/xml" "encoding/xml"

View File

@ -1,4 +1,4 @@
package xmpp package xmpp // import "fluux.io/xmpp"
import ( import (
"encoding/xml" "encoding/xml"