# HG changeset patch # User Chris Jones # Date 1324750732 25200 # Node ID a8fbec71a194a21c98c48439b76aa95d8842fd83 # Parent 6121aa2f21b163cbd485ed9964d3e82488e3f4e5 Added an interactive test and made Client implement io.Closer. diff -r 6121aa2f21b1 -r a8fbec71a194 examples/interact.go --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/interact.go Sat Dec 24 11:18:52 2011 -0700 @@ -0,0 +1,31 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "cjyar/xmpp" + "flag" + "log" + "os" + ) + +// Demonstrate the API, and allow the user to interact with an XMPP +// server via the terminal. +func main() { + var jid xmpp.JID + flag.Var(&jid, "jid", "JID to log in as") + var pw *string = flag.String("pw", "", "password") + flag.Parse() + if jid.Domain == "" || *pw == "" { + flag.Usage() + os.Exit(2) + } + + c, err := xmpp.NewClient(&jid, *pw) + if err != nil { + log.Fatalf("NewClient(%v): %v", jid, err) + } + defer c.Close() +} diff -r 6121aa2f21b1 -r a8fbec71a194 xmpp.go --- a/xmpp.go Sat Dec 24 11:05:54 2011 -0700 +++ b/xmpp.go Sat Dec 24 11:18:52 2011 -0700 @@ -8,6 +8,7 @@ import ( "fmt" + "io" "net" "os" ) @@ -23,6 +24,7 @@ //Out chan<- *Stanza tcp *net.TCPConn } +var _ io.Closer = &Client{} // Connect to the appropriate server and authenticate as the given JID // with the given password. @@ -58,3 +60,7 @@ cl.tcp = c return &cl, nil } + +func (c *Client) Close() os.Error { + return c.tcp.Close() +}