examples/interact.go
author Chris Jones <chris@cjones.org>
Sat, 24 Dec 2011 13:11:36 -0700
changeset 5 faef59c8db05
parent 4 a8fbec71a194
child 6 8e425e340ca1
permissions -rw-r--r--
Added a goroutine to read data from the remote and parse it into appropriate structures.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
     1
// Copyright 2011 The Go Authors.  All rights reserved.
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
     2
// Use of this source code is governed by a BSD-style
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
     3
// license that can be found in the LICENSE file.
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
     4
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
     5
package main
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
     6
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
     7
import (
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
     8
	"cjyar/xmpp"
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
     9
	"flag"
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    10
	"log"
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    11
	"os"
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    12
	)
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    13
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    14
// Demonstrate the API, and allow the user to interact with an XMPP
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    15
// server via the terminal.
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    16
func main() {
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    17
	var jid xmpp.JID
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    18
	flag.Var(&jid, "jid", "JID to log in as")
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    19
	var pw *string = flag.String("pw", "", "password")
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    20
	flag.Parse()
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    21
	if jid.Domain == "" || *pw == "" {
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    22
		flag.Usage()
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    23
		os.Exit(2)
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    24
	}
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    25
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    26
	c, err := xmpp.NewClient(&jid, *pw)
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    27
	if err != nil {
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    28
		log.Fatalf("NewClient(%v): %v", jid, err)
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    29
	}
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    30
	defer c.Close()
a8fbec71a194 Added an interactive test and made Client implement io.Closer.
Chris Jones <chris@cjones.org>
parents:
diff changeset
    31
}