Update the README.md file

I am assuming the code given in the "Using the framework" should run.

* Using client's consts, such as CONNECTED.
* In Go 1.4, `error` implements only the `Error()` function.
* The `c` variable is already declared in line 5, no need for `:=` in line 12
This commit is contained in:
Boaz Shuster 2015-08-19 10:24:05 +03:00
parent fdb1c8229d
commit 7252b8c67e
1 changed files with 12 additions and 7 deletions

View File

@ -16,7 +16,13 @@ old `go1` API.
Synopsis: Synopsis:
import irc "github.com/fluffle/goirc/client" package main
import (
"fmt"
irc "github.com/fluffle/goirc/client"
)
func main() { func main() {
// Creating a simple IRC client is simple. // Creating a simple IRC client is simple.
@ -27,20 +33,20 @@ Synopsis:
cfg.SSL = true cfg.SSL = true
cfg.Server = "irc.freenode.net:7000" cfg.Server = "irc.freenode.net:7000"
cfg.NewNick = func(n string) string { return n + "^" } cfg.NewNick = func(n string) string { return n + "^" }
c := irc.Client(cfg) c = irc.Client(cfg)
// Add handlers to do things here! // Add handlers to do things here!
// e.g. join a channel on connect. // e.g. join a channel on connect.
c.HandleFunc("connected", c.HandleFunc(irc.CONNECTED,
func(conn *irc.Conn, line *irc.Line) { conn.Join("#channel") }) func(conn *irc.Conn, line *irc.Line) { conn.Join("#channel") })
// And a signal on disconnect // And a signal on disconnect
quit := make(chan bool) quit := make(chan bool)
c.HandleFunc("disconnected", c.HandleFunc(irc.DISCONNECTED,
func(conn *irc.Conn, line *irc.Line) { quit <- true }) func(conn *irc.Conn, line *irc.Line) { quit <- true })
// Tell client to connect. // Tell client to connect.
if err := c.Connect(); err != nil { if err := c.Connect(); err != nil {
fmt.Printf("Connection error: %s\n", err.String()) fmt.Printf("Connection error: %s\n", err.Error())
} }
// With a "simple" client, set Server before calling Connect... // With a "simple" client, set Server before calling Connect...
@ -48,7 +54,7 @@ Synopsis:
// ... or, use ConnectTo instead. // ... or, use ConnectTo instead.
if err := c.ConnectTo("irc.freenode.net"); err != nil { if err := c.ConnectTo("irc.freenode.net"); err != nil {
fmt.Printf("Connection error: %s\n", err.String()) fmt.Printf("Connection error: %s\n", err.Error())
} }
// Wait for disconnect // Wait for disconnect
@ -94,4 +100,3 @@ Contributions gratefully received from:
- [StalkR](https://github.com/StalkR) - [StalkR](https://github.com/StalkR)
- [sztanpet](https://github.com/sztanpet) - [sztanpet](https://github.com/sztanpet)
- [wathiede](https://github.com/wathiede) - [wathiede](https://github.com/wathiede)