Skip to content

Instantly share code, notes, and snippets.

@kzisme
Created December 16, 2017 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kzisme/65dc266170d988df867d447614c33f63 to your computer and use it in GitHub Desktop.
Save kzisme/65dc266170d988df867d447614c33f63 to your computer and use it in GitHub Desktop.
// Defining a struct named WhoIsCommand
// Has 3 fields
// 1. Base Command Type
// 2. target of type Name
// 3. masks of type array name
type WhoisCommand struct {
BaseCommand
target Name
masks []Name
}
// Function that takes argumemnts as a string array and a command (in this case /whois)
// WHOIS [ <target> ] <mask> *( "," <mask> )
func ParseWhoisCommand(args []string) (Command, error) {
// Checking if we actually have an argument
if len(args) < 1 {
return nil, NotEnoughArgsError
}
// Creating two variables of type string named masks and target
var masks string
var target string
// Checking if we have more than one argument
// If we do assigning the passed in variable to our newly created ones
if len(args) > 1 {
target = args[0]
masks = args[1]
} else {
// If we have have one argument assigning our arguments to masks
masks = args[0]
}
// Returning the WhoIsCommand by reference.
// See: (https://github.com/prologic/eris/blob/233238b709626fb40a8bd637674e0208746e8b33/irc/server.go#L656)
// See: (RplWhois /irc/reply.go)
return &WhoisCommand{
target: NewName(target),
masks: NewNames(strings.Split(masks, ",")),
}, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment