From 699a3d75a6a5c3cbdb70eb2b7c67db045fd0d494 Mon Sep 17 00:00:00 2001 From: shoopea Date: Thu, 16 Jan 2020 23:18:25 +0800 Subject: [PATCH] test --- client.go | 5 +++++ def.go | 18 +++++++++--------- workers.go | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/client.go b/client.go index 5d0c986..5d5d942 100644 --- a/client.go +++ b/client.go @@ -32,8 +32,13 @@ func loadClients() error { cx := ChirpClient{} copier.Copy(&cx, &c) cx.Active = false + /* + cx.MQ.Connection, err = amqp.Dial("amqp://" + cx.MQ.User + ":" + cx.MQ.Password + "@" + cx.MQ.Host + "/" + cx.MQ.Path) + logOnError(err, "loadClients : Failed to connect to RabbitMQ") + */ clients[cx.TGUserID64] = &cx log.Printf("loadClients[%s] : done\n", cx.Login) + } muxClients.Unlock() diff --git a/def.go b/def.go index be3ce72..ca36c96 100644 --- a/def.go +++ b/def.go @@ -62,14 +62,14 @@ type ObjSubType struct { } type MQClient struct { - User string - Password string - Host string - Path string - SSL bool - Connection *amqp.Connection - Channel *amqp.Channel - Queue amqp.Queue + User string `json:"user"` + Password string `json:"passwd"` + Host string `json:"host"` + Path string `json:"path"` + SSL bool `json:"ssl"` + Connection *amqp.Connection `json:"-"` + Channel *amqp.Channel `json:"-"` + Queue amqp.Queue `json:"-"` } type ChirpClient struct { @@ -77,7 +77,7 @@ type ChirpClient struct { Login string `json:"nickname"` Active bool `json:"active"` TGUserID64 int64 `json:"tg_user_id"` - MQ MQClient `json:"-"` + MQ MQClient `json:"mq"` CWUserID64 int64 `json:"user_id"` CWGuildID64 int64 `json:"guild_id"` CWRole string `json:"role"` diff --git a/workers.go b/workers.go index ece0151..5bfb099 100644 --- a/workers.go +++ b/workers.go @@ -252,7 +252,7 @@ func MQTGCmdWorker(id int, cmds <-chan TGCommand) { j, err := json.Marshal(c) logOnError(err, "MQTGCmdWorker["+strconv.Itoa(id)+"] : Marshal(c)") //log.Printf("MQTGCmdWorker["+strconv.Itoa(id)+"] : new command.\n%s\n", string(j)) - for clt.MQ.Connection.IsClosed() { + for clt.MQ.Connection == nil || clt.MQ.Connection.IsClosed() { clt.Active = false log.Printf("MQTGCmdWorker : Resetting MQ connection for #%d.\n", c.FromUserID64) clt.MQ.Connection, err = amqp.Dial("amqp://" + clt.MQ.User + ":" + clt.MQ.Password + "@" + clt.MQ.Host + "/" + clt.MQ.Path)