1
0
Fork 0
forked from External/ergo

Mostly style stuff.

This commit is contained in:
Jeremy Latt 2013-05-09 11:05:10 -07:00
parent 39f815df01
commit 65af2b4320
7 changed files with 112 additions and 100 deletions

View file

@ -6,8 +6,32 @@ import (
"strings"
)
type Command interface {
Client() *Client
HandleServer(*Server)
}
type EditableCommand interface {
Command
SetClient(*Client)
}
var (
NotEnoughArgsError = errors.New("not enough arguments")
ErrParseCommand = errors.New("failed to parse message")
parseCommandFuncs = map[string]func([]string) (EditableCommand, error){
"JOIN": NewJoinCommand,
"MODE": NewModeCommand,
"NICK": NewNickCommand,
"PART": NewPartCommand,
"PASS": NewPassCommand,
"PING": NewPingCommand,
"PONG": NewPongCommand,
"PRIVMSG": NewPrivMsgCommand,
"QUIT": NewQuitCommand,
"TOPIC": NewTopicCommand,
"USER": NewUserMsgCommand,
}
)
type BaseCommand struct {
@ -25,28 +49,6 @@ func (base *BaseCommand) SetClient(c *Client) {
base.client = c
}
type EditableCommand interface {
Command
SetClient(*Client)
}
var (
ErrParseCommand = errors.New("failed to parse message")
parseCommandFuncs = map[string]func([]string) (EditableCommand, error){
"JOIN": NewJoinCommand,
"MODE": NewModeCommand,
"NICK": NewNickCommand,
"PART": NewPartCommand,
"PASS": NewPassCommand,
"PING": NewPingCommand,
"PONG": NewPongCommand,
"PRIVMSG": NewPrivMsgCommand,
"QUIT": NewQuitCommand,
"TOPIC": NewTopicCommand,
"USER": NewUserMsgCommand,
}
)
func ParseCommand(line string) (EditableCommand, error) {
command, args := parseLine(line)
constructor := parseCommandFuncs[command]