mattn/go-xmpp — pull request #20 by swdunlop (2013-08-12 23:06:05+00:00)
Title: Add Options structure to consolidate NewClient arguments, and add Resource binding

This pull request adds an Options structure which combines all of the current arguments used for NewClient to create a more extensible way to create new XMPP client connections. The logic used by the original NewClient and NewClientNoTLS are pulled into a method of Options, and wrappers left in their place to preserve API compatibility.

Example Use of the new API:

for {
var err error
client, err = xmpp.Options{
Host: Config.Xmpp.Addr,
User: Config.Xmpp.User,
Password: Config.Xmpp.Password,
Resource: "bot",
}.NewClient()

if err != nil {
complain("xmpp-connect", err)
time.Sleep(5 * time.Second)
continue
}
for _, room := range Config.Xmpp.Rooms {
client.JoinMUC(room + "/" + Config.Xmpp.Nick)
}
break
}

This was done to enable binding the client to a named XMPP resource at connection time, which is useful for HipChat bots to declare a resource of `bot` at runtime. This also means that additional options can be added without breaking existing clients.

Let me know what you think, I release my changes in this pull request into the public domain.