This commit is contained in:
shoopea 2020-01-16 23:18:25 +08:00
parent ee47b8058b
commit 699a3d75a6
3 changed files with 15 additions and 10 deletions

View File

@ -32,8 +32,13 @@ func loadClients() error {
cx := ChirpClient{} cx := ChirpClient{}
copier.Copy(&cx, &c) copier.Copy(&cx, &c)
cx.Active = false 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 clients[cx.TGUserID64] = &cx
log.Printf("loadClients[%s] : done\n", cx.Login) log.Printf("loadClients[%s] : done\n", cx.Login)
} }
muxClients.Unlock() muxClients.Unlock()

18
def.go
View File

@ -62,14 +62,14 @@ type ObjSubType struct {
} }
type MQClient struct { type MQClient struct {
User string User string `json:"user"`
Password string Password string `json:"passwd"`
Host string Host string `json:"host"`
Path string Path string `json:"path"`
SSL bool SSL bool `json:"ssl"`
Connection *amqp.Connection Connection *amqp.Connection `json:"-"`
Channel *amqp.Channel Channel *amqp.Channel `json:"-"`
Queue amqp.Queue Queue amqp.Queue `json:"-"`
} }
type ChirpClient struct { type ChirpClient struct {
@ -77,7 +77,7 @@ type ChirpClient struct {
Login string `json:"nickname"` Login string `json:"nickname"`
Active bool `json:"active"` Active bool `json:"active"`
TGUserID64 int64 `json:"tg_user_id"` TGUserID64 int64 `json:"tg_user_id"`
MQ MQClient `json:"-"` MQ MQClient `json:"mq"`
CWUserID64 int64 `json:"user_id"` CWUserID64 int64 `json:"user_id"`
CWGuildID64 int64 `json:"guild_id"` CWGuildID64 int64 `json:"guild_id"`
CWRole string `json:"role"` CWRole string `json:"role"`

View File

@ -252,7 +252,7 @@ func MQTGCmdWorker(id int, cmds <-chan TGCommand) {
j, err := json.Marshal(c) j, err := json.Marshal(c)
logOnError(err, "MQTGCmdWorker["+strconv.Itoa(id)+"] : Marshal(c)") logOnError(err, "MQTGCmdWorker["+strconv.Itoa(id)+"] : Marshal(c)")
//log.Printf("MQTGCmdWorker["+strconv.Itoa(id)+"] : new command.\n%s\n", string(j)) //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 clt.Active = false
log.Printf("MQTGCmdWorker : Resetting MQ connection for #%d.\n", c.FromUserID64) 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) clt.MQ.Connection, err = amqp.Dial("amqp://" + clt.MQ.User + ":" + clt.MQ.Password + "@" + clt.MQ.Host + "/" + clt.MQ.Path)