mirror of https://github.com/fluffle/goirc
Run gofmt over code, it's been a while.
This commit is contained in:
parent
18c20080e8
commit
c400a2141a
|
@ -40,7 +40,7 @@ func main() {
|
|||
}
|
||||
// no point in sending empty lines down the channel
|
||||
if len(s) > 2 {
|
||||
in <- s[0:len(s)-1]
|
||||
in <- s[0 : len(s)-1]
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
|
@ -14,18 +14,18 @@ import "strings"
|
|||
func (conn *Conn) Raw(rawline string) { conn.out <- rawline }
|
||||
|
||||
// Pass() sends a PASS command to the server
|
||||
func (conn *Conn) Pass(password string) { conn.out <- "PASS "+password }
|
||||
func (conn *Conn) Pass(password string) { conn.out <- "PASS " + password }
|
||||
|
||||
// Nick() sends a NICK command to the server
|
||||
func (conn *Conn) Nick(nick string) { conn.out <- "NICK "+nick }
|
||||
func (conn *Conn) Nick(nick string) { conn.out <- "NICK " + nick }
|
||||
|
||||
// User() sends a USER command to the server
|
||||
func (conn *Conn) User(ident, name string) {
|
||||
conn.out <- "USER "+ident+" 12 * :"+name
|
||||
conn.out <- "USER " + ident + " 12 * :" + name
|
||||
}
|
||||
|
||||
// Join() sends a JOIN command to the server
|
||||
func (conn *Conn) Join(channel string) { conn.out <- "JOIN "+channel }
|
||||
func (conn *Conn) Join(channel string) { conn.out <- "JOIN " + channel }
|
||||
|
||||
// Part() sends a PART command to the server with an optional part message
|
||||
func (conn *Conn) Part(channel string, message ...string) {
|
||||
|
@ -33,7 +33,7 @@ func (conn *Conn) Part(channel string, message ...string) {
|
|||
if msg != "" {
|
||||
msg = " :" + msg
|
||||
}
|
||||
conn.out <- "PART "+channel+msg
|
||||
conn.out <- "PART " + channel + msg
|
||||
}
|
||||
|
||||
// Kick() sends a KICK command to remove a nick from a channel
|
||||
|
@ -42,7 +42,7 @@ func (conn *Conn) Kick(channel, nick string, message ...string) {
|
|||
if msg != "" {
|
||||
msg = " :" + msg
|
||||
}
|
||||
conn.out <- "KICK "+channel+" "+nick+msg
|
||||
conn.out <- "KICK " + channel + " " + nick + msg
|
||||
}
|
||||
|
||||
// Quit() sends a QUIT command to the server with an optional quit message
|
||||
|
@ -51,20 +51,20 @@ func (conn *Conn) Quit(message ...string) {
|
|||
if msg == "" {
|
||||
msg = "GoBye!"
|
||||
}
|
||||
conn.out <- "QUIT :"+msg
|
||||
conn.out <- "QUIT :" + msg
|
||||
}
|
||||
|
||||
// Whois() sends a WHOIS command to the server
|
||||
func (conn *Conn) Whois(nick string) { conn.out <- "WHOIS "+nick }
|
||||
func (conn *Conn) Whois(nick string) { conn.out <- "WHOIS " + nick }
|
||||
|
||||
//Who() sends a WHO command to the server
|
||||
func (conn *Conn) Who(nick string) { conn.out <- "WHO "+nick }
|
||||
func (conn *Conn) Who(nick string) { conn.out <- "WHO " + nick }
|
||||
|
||||
// Privmsg() sends a PRIVMSG to the target t
|
||||
func (conn *Conn) Privmsg(t, msg string) { conn.out <- "PRIVMSG "+t+" :"+msg }
|
||||
func (conn *Conn) Privmsg(t, msg string) { conn.out <- "PRIVMSG " + t + " :" + msg }
|
||||
|
||||
// Notice() sends a NOTICE to the target t
|
||||
func (conn *Conn) Notice(t, msg string) { conn.out <- "NOTICE "+t+" :"+msg }
|
||||
func (conn *Conn) Notice(t, msg string) { conn.out <- "NOTICE " + t + " :" + msg }
|
||||
|
||||
// Ctcp() sends a (generic) CTCP message to the target t
|
||||
// with an optional argument
|
||||
|
@ -100,7 +100,7 @@ func (conn *Conn) Topic(channel string, topic ...string) {
|
|||
if t != "" {
|
||||
t = " :" + t
|
||||
}
|
||||
conn.out <- "TOPIC "+channel+t
|
||||
conn.out <- "TOPIC " + channel + t
|
||||
}
|
||||
|
||||
// Mode() sends a MODE command to the server. This one can get complicated if
|
||||
|
@ -115,7 +115,7 @@ func (conn *Conn) Mode(t string, modestring ...string) {
|
|||
if mode != "" {
|
||||
mode = " " + mode
|
||||
}
|
||||
conn.out <- "MODE "+t+mode
|
||||
conn.out <- "MODE " + t + mode
|
||||
}
|
||||
|
||||
// Away() sends an AWAY command to the server
|
||||
|
@ -126,15 +126,15 @@ func (conn *Conn) Away(message ...string) {
|
|||
if msg != "" {
|
||||
msg = " :" + msg
|
||||
}
|
||||
conn.out <- "AWAY"+msg
|
||||
conn.out <- "AWAY" + msg
|
||||
}
|
||||
|
||||
// Invite() sends an INVITE command to the server
|
||||
func (conn *Conn) Invite(nick, channel string) {
|
||||
conn.out <- "INVITE "+nick+" "+channel
|
||||
conn.out <- "INVITE " + nick + " " + channel
|
||||
}
|
||||
|
||||
// Oper() sends an OPER command to the server
|
||||
func (conn *Conn) Oper(user, pass string) {
|
||||
conn.out <- "OPER "+user+" "+pass
|
||||
conn.out <- "OPER " + user + " " + pass
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ type Conn struct {
|
|||
Network string
|
||||
|
||||
// Event handler registry and dispatcher
|
||||
Registry event.EventRegistry
|
||||
Registry event.EventRegistry
|
||||
Dispatcher event.EventDispatcher
|
||||
|
||||
// Map of channels we're on
|
||||
|
@ -76,21 +76,21 @@ type Conn struct {
|
|||
func New(nick, user, name string) *Conn {
|
||||
reg := event.NewRegistry()
|
||||
conn := &Conn{
|
||||
Registry: reg,
|
||||
Registry: reg,
|
||||
Dispatcher: reg,
|
||||
in: make(chan *Line, 32),
|
||||
out: make(chan string, 32),
|
||||
Err: make(chan os.Error, 4),
|
||||
cSend: make(chan bool),
|
||||
cLoop: make(chan bool),
|
||||
SSL: false,
|
||||
SSLConfig: nil,
|
||||
Timeout: 300,
|
||||
Flood: false,
|
||||
badness: 0,
|
||||
lastsent: 0,
|
||||
Timestamp: time.LocalTime,
|
||||
TSFormat: "15:04:05",
|
||||
in: make(chan *Line, 32),
|
||||
out: make(chan string, 32),
|
||||
Err: make(chan os.Error, 4),
|
||||
cSend: make(chan bool),
|
||||
cLoop: make(chan bool),
|
||||
SSL: false,
|
||||
SSLConfig: nil,
|
||||
Timeout: 300,
|
||||
Flood: false,
|
||||
badness: 0,
|
||||
lastsent: 0,
|
||||
Timestamp: time.LocalTime,
|
||||
TSFormat: "15:04:05",
|
||||
}
|
||||
conn.initialise()
|
||||
conn.SetupHandlers()
|
||||
|
|
|
@ -28,7 +28,7 @@ func Test001(t *testing.T) {
|
|||
c.h_001(parseLine(":irc.server.org 001 test :Welcome to IRC test!ident@somehost.com"))
|
||||
// Should result in no response to server
|
||||
m.ExpectNothing()
|
||||
|
||||
|
||||
// Check that the event was dispatched correctly
|
||||
if !flag {
|
||||
t.Errorf("Sending 001 didn't result in dispatch of connected event.")
|
||||
|
@ -54,7 +54,7 @@ func Test433(t *testing.T) {
|
|||
t.Errorf("ReNick() called unexpectedly, Nick == '%s'.", c.Me.Nick)
|
||||
}
|
||||
|
||||
// Send a line that will trigger a renick. This happens when our wanted
|
||||
// Send a line that will trigger a renick. This happens when our wanted
|
||||
// nick is unavailable during initial negotiation, so we must choose a
|
||||
// different one before the connection can proceed. No NICK line will be
|
||||
// sent by the server to confirm nick change in this case.
|
||||
|
@ -346,8 +346,8 @@ func TestMODE(t *testing.T) {
|
|||
cm := test1.Modes
|
||||
|
||||
// Verify the ChanPrivs exists and modes we're testing aren't set
|
||||
if cp, ok := user1.Channels[test1]; (!ok || c.Me.Channels[test1].Voice ||
|
||||
cp.Op || cm.Key != "" || cm.InviteOnly || cm.Secret) {
|
||||
if cp, ok := user1.Channels[test1]; !ok || c.Me.Channels[test1].Voice ||
|
||||
cp.Op || cm.Key != "" || cm.InviteOnly || cm.Secret {
|
||||
t.Errorf("Channel privileges in unexpected state before MODE.")
|
||||
}
|
||||
|
||||
|
@ -589,8 +589,7 @@ func Test353(t *testing.T) {
|
|||
t.Errorf("353 handler failed to op known nick user1.")
|
||||
}
|
||||
|
||||
if p := get("user2");
|
||||
p == nil || p.Voice || p.HalfOp || p.Op || p.Admin || p.Owner {
|
||||
if p := get("user2"); p == nil || p.Voice || p.HalfOp || p.Op || p.Admin || p.Owner {
|
||||
t.Errorf("353 handler set modes on new nick user2.")
|
||||
}
|
||||
|
||||
|
|
|
@ -14,13 +14,13 @@ type mockNetConn struct {
|
|||
In, Out chan string
|
||||
in, out chan []byte
|
||||
closers []chan bool
|
||||
rc chan bool
|
||||
rc chan bool
|
||||
|
||||
closed bool
|
||||
rt, wt int64
|
||||
}
|
||||
|
||||
func MockNetConn(t *testing.T) (*mockNetConn) {
|
||||
func MockNetConn(t *testing.T) *mockNetConn {
|
||||
// Our mock connection is a testing object
|
||||
m := &mockNetConn{T: t}
|
||||
m.closers = make([]chan bool, 0, 3)
|
||||
|
@ -78,13 +78,13 @@ func (m *mockNetConn) Expect(e string) {
|
|||
t := time.NewTimer(5e6)
|
||||
select {
|
||||
case <-t.C:
|
||||
m.Errorf("Mock connection did not receive expected output.\n\t" +
|
||||
m.Errorf("Mock connection did not receive expected output.\n\t"+
|
||||
"Expected: '%s', got nothing.", e)
|
||||
case s := <-m.Out:
|
||||
t.Stop()
|
||||
s = strings.Trim(s, "\r\n")
|
||||
if e != s {
|
||||
m.Errorf("Mock connection received unexpected value.\n\t" +
|
||||
m.Errorf("Mock connection received unexpected value.\n\t"+
|
||||
"Expected: '%s'\n\tGot: '%s'", e, s)
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ func (m *mockNetConn) ExpectNothing() {
|
|||
case s := <-m.Out:
|
||||
t.Stop()
|
||||
s = strings.Trim(s, "\r\n")
|
||||
m.Errorf("Mock connection received unexpected output.\n\t" +
|
||||
m.Errorf("Mock connection received unexpected output.\n\t"+
|
||||
"Expected nothing, got: '%s'", s)
|
||||
}
|
||||
}
|
||||
|
@ -140,11 +140,11 @@ func (m *mockNetConn) Close() os.Error {
|
|||
}
|
||||
|
||||
func (m *mockNetConn) LocalAddr() net.Addr {
|
||||
return &net.IPAddr{net.IPv4(127,0,0,1)}
|
||||
return &net.IPAddr{net.IPv4(127, 0, 0, 1)}
|
||||
}
|
||||
|
||||
func (m *mockNetConn) RemoteAddr() net.Addr {
|
||||
return &net.IPAddr{net.IPv4(127,0,0,1)}
|
||||
return &net.IPAddr{net.IPv4(127, 0, 0, 1)}
|
||||
}
|
||||
|
||||
func (m *mockNetConn) SetTimeout(ns int64) os.Error {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
)
|
||||
|
||||
type HandlerID uint32
|
||||
|
||||
var hidCounter uint32 = 0
|
||||
|
||||
func NewHandlerID() HandlerID {
|
||||
|
@ -20,8 +21,8 @@ type Handler interface {
|
|||
}
|
||||
|
||||
type basicHandler struct {
|
||||
fn func(...interface{})
|
||||
id HandlerID
|
||||
fn func(...interface{})
|
||||
id HandlerID
|
||||
}
|
||||
|
||||
func (h *basicHandler) Run(ev ...interface{}) {
|
||||
|
@ -37,7 +38,7 @@ func NewHandler(h func(...interface{})) Handler {
|
|||
}
|
||||
|
||||
type EventDispatcher interface {
|
||||
Dispatch(name string, ev...interface{})
|
||||
Dispatch(name string, ev ...interface{})
|
||||
}
|
||||
|
||||
type EventRegistry interface {
|
||||
|
@ -50,9 +51,9 @@ type EventRegistry interface {
|
|||
type registry struct {
|
||||
// Event registry as a lockable map of linked-lists
|
||||
sync.RWMutex
|
||||
events map[string]*list.List
|
||||
events map[string]*list.List
|
||||
dispatcher func(r *registry, name string, ev ...interface{})
|
||||
}
|
||||
}
|
||||
|
||||
func NewRegistry() EventRegistry {
|
||||
r := ®istry{events: make(map[string]*list.List)}
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
func TestSimpleDispatch(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
out := make(chan bool)
|
||||
|
||||
|
||||
h := NewHandler(func(ev ...interface{}) {
|
||||
out <- ev[0].(bool)
|
||||
})
|
||||
|
@ -41,7 +41,7 @@ func TestParallelDispatch(t *testing.T) {
|
|||
}
|
||||
|
||||
// create some handlers and send an event to them
|
||||
for _, t := range []int{5,11,2,15,8} {
|
||||
for _, t := range []int{5, 11, 2, 15, 8} {
|
||||
r.AddHandler("send", factory(t))
|
||||
}
|
||||
r.Dispatch("send")
|
||||
|
@ -79,7 +79,7 @@ func TestSerialDispatch(t *testing.T) {
|
|||
}
|
||||
|
||||
// create some handlers and send an event to them
|
||||
for _, t := range []int{5,11,2,15,8} {
|
||||
for _, t := range []int{5, 11, 2, 15, 8} {
|
||||
r.AddHandler("send", factory(t))
|
||||
}
|
||||
r.Dispatch("send")
|
||||
|
@ -101,4 +101,3 @@ func TestSerialDispatch(t *testing.T) {
|
|||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue