func (irc *MockIRC) connectionWorker(conn net.Conn) {
	irc.io = bufio.NewReadWriter(
		bufio.NewReader(conn),
		bufio.NewWriter(conn))
	defer conn.Close()
	for {
		msg, err := irc.io.ReadString('\n')
		if err != nil {
			if !irc.stop {
				if err == io.EOF {
					log.Println(err)
				}
			}
			return
		}
		irc.handleMessage(msg)
	}
}
connectionWorker will handle incoming connections from Accept.
Runs in it's own goroutine.
package mockirc
import (
	"bufio"
	"fmt"
	"io"
	"log"
	"net"
	"strings"
	"time"
)
type MockIRC struct {
	Port       int
	ServerName string
	Socket     net.Listener
	events     map[string]*WhenEvent
	io         *bufio.ReadWriter
	stop       bool
}
func New(server string, port int) *MockIRC {
	irc := &MockIRC{}
	if port == 0 {
		irc.Port = 6661
	} else {
		irc.Port = port
	}
	irc.ServerName = server
	irc.events = make(map[string]*WhenEvent)
	return irc
}
func (irc *MockIRC) Start() (chan bool, error) {
	wait := make(chan bool, 1)
	sock, err := net.Listen("tcp", fmt.Sprintf(":%d", irc.Port))
	if err != nil {
		return nil, err
	}
	irc.Socket = sock
	go func() {
		defer close(wait)
		accept := func() <-chan net.Conn {
			a := make(chan net.Conn)
			go func() {
				for {
					conn, err := irc.Socket.Accept()
					if err != nil {
						if irc.stop {
							return
						}
						log.Println(err)
						continue
					}
					if conn != nil {
						a <- conn
					}
				}
			}()
			return a
		}()
		wait <- true
		for {
			conn := <-accept
			if irc.stop {
				return
			}
			go irc.connectionWorker(conn)
		}
	}()
	return wait, nil
}
func (irc *MockIRC) Stop() error {
	if irc.stop {
		return nil
	}
	irc.stop = true
	err := irc.Socket.Close()
	if err != nil {
		return err
	}
	<-time.After(time.Second)
	return nil
}