change var

This commit is contained in:
shoopea 2019-05-15 10:36:57 +08:00
parent b1a33e277b
commit 1a9fe28549

5
mq.go
View File

@ -52,6 +52,7 @@ func MQSendMsgWorker(id int, msgs <-chan ChatWarsMessage) {
} }
func MQReceiveMsgWorker(id int, cmd chan<- ChatWarsCommand) { func MQReceiveMsgWorker(id int, cmd chan<- ChatWarsCommand) {
var c ChatWarsCommand
conn, err := amqp.Dial("amqp://" + cfg.Rabbit.User + ":" + cfg.Rabbit.Password + "@" + cfg.Rabbit.Host + "/" + cfg.Rabbit.ReceiveQueue) conn, err := amqp.Dial("amqp://" + cfg.Rabbit.User + ":" + cfg.Rabbit.Password + "@" + cfg.Rabbit.Host + "/" + cfg.Rabbit.ReceiveQueue)
failOnError(err, "MQReceiveMsgWorker["+strconv.Itoa(id)+"] : Failed to connect to RabbitMQ") failOnError(err, "MQReceiveMsgWorker["+strconv.Itoa(id)+"] : Failed to connect to RabbitMQ")
defer conn.Close() defer conn.Close()
@ -83,10 +84,10 @@ func MQReceiveMsgWorker(id int, cmd chan<- ChatWarsCommand) {
for d := range m { for d := range m {
// log.Printf("MQReceiveMsgWorker["+strconv.Itoa(id)+"] : Received a message: %s", string(d.Body)) // log.Printf("MQReceiveMsgWorker["+strconv.Itoa(id)+"] : Received a message: %s", string(d.Body))
err = json.Unmarshal(d.Body, &x) err = json.Unmarshal(d.Body, &c)
logOnError(err, "MQReceiveMsgWorker["+strconv.Itoa(id)+"] : Can't unmarshal.\n"+string(d.Body)) logOnError(err, "MQReceiveMsgWorker["+strconv.Itoa(id)+"] : Can't unmarshal.\n"+string(d.Body))
if err == nil { if err == nil {
cmd <- x cmd <- c
} }
} }