func Boot() { /* Setup our command line arguments */ web_server := flag.Int("web", 80, "Port to run the webserver") socket_server := flag.Int("socket", 8080, "Port to run the websocket server") signature := flag.String("signature", "hal", "Master password to be used") workers := flag.Int("workers", 100, "How many workers to spin up") master_signature = *signature flag.Parse() log.Info("Good Morning Dave ...") /* TODO: Remove me */ users.Register(&users.Info{ Username: "******", Signature: master_signature, Channels: map[string]int{}, }) /* Create a few channels */ msgs := make(chan *message.Message) /* Get our message workers up and running */ for x := 1; x <= *workers; x++ { go MessageWorker(x, msgs) } /* Start Hal's webserver in the background */ go web.Boot(*web_server, msgs) /* Start Hal's websocket server */ go socket.Boot(*socket_server, msgs) }
func (c *command) Execute() { cmd_split := strings.Split(string(c.cmd_raw[1:]), " ") for index, word := range cmd_split { switch index { case 0: c.cmd = word case 1: c.modifier = word case 2: c.param1 = word } } switch c.cmd { default: log.Error("Unknown command " + c.cmd) case "register": u := &users.Info{ Username: c.modifier, Signature: c.param1, } if user, err := users.Register(u); err == nil { log.Info(user.At() + " registered") } else { log.Error(err.Error()) } case "leave": if user, err := users.Fetch(c.executor); err == nil { user.LeaveChannel(c.modifier) log.Info(user.At() + " left " + c.modifier) } else { log.Error("Unknown user " + c.executor) } case "join": if user, err := users.Fetch(c.executor); err == nil { user.JoinChannel(c.modifier, 1) log.Info(user.At() + " joined " + c.modifier) } else { log.Error("Unknown user " + c.executor) } } }