Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
Adds a few examples to the documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorcix committed Dec 1, 2015
1 parent 6e158ef commit c1a05c9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
25 changes: 25 additions & 0 deletions message_test.go
Expand Up @@ -5,10 +5,35 @@
package irc

import (
"fmt"
"reflect"
"testing"
)

func ExampleParseMessage() {
message := ParseMessage("JOIN #help")

fmt.Println(message.Params[0])

// Output: #help
}

func ExampleMessage_String() {
message := &Message{
Prefix: &Prefix{
Name: "sorcix",
User: "sorcix",
Host: "myhostname",
},
Command: "PRIVMSG",
Trailing: "This is an example!",
}

fmt.Println(message.String())

// Output: :sorcix!sorcix@myhostname PRIVMSG :This is an example!
}

var messageTests = [...]*struct {
parsed *Message
rawMessage string
Expand Down
24 changes: 24 additions & 0 deletions stream_test.go
Expand Up @@ -6,12 +6,36 @@ package irc

import (
"bytes"
"crypto/tls"
"io"
"log"
"reflect"
"strings"
"testing"
)

// We use the Dial function as a simple shortcut for connecting to an IRC server using a standard TCP socket.
func ExampleDial() {
conn, err := Dial("irc.quakenet.org:6667")
if err != nil {
log.Fatalln("Could not connect to IRC server")
}

conn.Close()
}

// Use NewConn when you want to connect using something else than a standard TCP socket.
// This example first opens an encrypted TLS connection and then uses that to communicate with the server.
func ExampleNewConn() {
tconn, err := tls.Dial("tcp", "irc.quakenet.org:6667", &tls.Config{})
if err != nil {
log.Fatalln("Could not connect to IRC server")
}
conn := NewConn(tconn)

conn.Close()
}

var stream = "PING port80a.se.quakenet.org\r\n:port80a.se.quakenet.org PONG port80a.se.quakenet.org :port80a.se.quakenet.org\r\nPING chat.freenode.net\r\n:wilhelm.freenode.net PONG wilhelm.freenode.net :chat.freenode.net\r\n"

var result = [...]*Message{
Expand Down

0 comments on commit c1a05c9

Please sign in to comment.