func (c *commandStrategy) msgQueryFail() error { c.app.RWMutex.RLock() defer c.app.RWMutex.RUnlock() logging.Debug("Sending message query fail from %s", c.app.Manifest.InstanceId) var id, message string if id_, ok := getString(c.body, "id"); ok { id = id_ } else { return errors.New("No id found") } if message_, ok := getString(c.body, "message"); !ok { message = message_ } else { return errors.New("No message found") } body := make(jsonData) body["fromInstanceId"] = c.app.Manifest.InstanceId body["id"] = id body["message"] = message if recipient, ok := msg_archive.GetMsg(id); ok { recipient.Send("MSG_QUERY_FAIL", body) } else { logging.Warning("unrecognized message query id %s from app %s", id, c.app.Manifest.InstanceId) } return nil }
func (c *commandStrategy) msgQuerySuccess() error { c.app.RWMutex.RLock() defer c.app.RWMutex.RUnlock() logging.Debug("Replying to message from app %s", c.app.Manifest.InstanceId) var id string if id_, ok := getString(c.body, "id"); ok { id = id_ } else { return errors.New("No id found") } ret := c.body["ret"] body := make(jsonData) body["fromInstanceId"] = c.app.Manifest.InstanceId body["id"] = id body["ret"] = ret if recipient, ok := msg_archive.GetMsg(id); ok { recipient.Send("MSG_QUERY_SUCCESS", body) } else { logging.Warning("unrecognized message query id %s from app %s", id, c.app.Manifest.InstanceId) } return nil }
// main parses command-line arguments and spawns a new server func main() { logging.SetLevel(logging.DEBUG) no_tls := flag.Bool("no-tls", false, "Whether to use TLS, default false") crt_path := flag.String("crt", "cert.crt", "Path to the TLS certificate, default `cert.crt`") key_path := flag.String("key", "key.key", "Path to the TLS key, default `key.key`") sname := flag.String("srv-name", "mycroft", "This server's name for SNI") flag.Parse() logging.Info("Starting Server ...") if *no_tls { logging.Warning("not using TLS") err := srv.StartListen(1847, false, "", "", "") if err != nil { logging.Fatal("Could not start server: ", err.Error()) } } else { err := srv.StartListen(1847, true, *crt_path, *key_path, *sname) if err != nil { logging.Fatal("Could not start server: ", err.Error()) } } }