func main() { r := runner.New(Name) if err := r.Init(); err != nil { log.Fatal(err) } if r.Kite == nil { r.Log.Fatal("couldnt init kite") } // remove QOS, we want to consume all the messages from RMQ if err := r.Bongo.Broker.Sub.(*broker.Consumer).Consumer.QOS(0); err != nil { r.Log.Fatal("couldnt remove the QOS %# v", err) } appConfig := config.MustRead(r.Conf.Path) // init mongo connection modelhelper.Initialize(appConfig.Mongo) defer modelhelper.Close() // init with defaults & ensure expireAt index mongoCache := cache.NewMongoCacheWithTTL(modelhelper.Mongo.Session, cache.StartGC(), cache.MustEnsureIndexExpireAt()) defer mongoCache.StopGC() handler := collaboration.New(r.Log, mongoCache, appConfig, r.Kite) r.SetContext(handler) // only listen and operate on collaboration ping messages that are fired by the handler r.Register(models.Ping{}).On(collaboration.FireEventName).Handle((*collaboration.Controller).Ping) r.Listen() r.Wait() }
func main() { r := runner.New(Name) if err := r.Init(); err != nil { log.Fatal(err) } // appConfig c := config.MustRead(r.Conf.Path) mc := mux.NewConfig(Name, r.Conf.Host, r.Conf.Port) mc.Debug = r.Conf.Debug m := mux.New(mc, r.Log, r.Metrics) // init mongo connection modelhelper.Initialize(c.Mongo) defer modelhelper.Close() // init mongo cache with ensured index mgoCache := cache.NewMongoCacheWithTTL(modelhelper.Mongo.Session, cache.StartGC(), cache.MustEnsureIndexExpireAt(), ) defer mgoCache.StopGC() handlers.AddHandlers(m) collaboration.AddHandlers(m, mgoCache) paymentapi.AddHandlers(m) mailapi.AddHandlers(m) algoliaapi.AddHandlers(m, r.Log) account.AddHandlers(m) channel.AddHandlers(m) client.AddHandlers(m) message.AddHandlers(m) messagelist.AddHandlers(m) participant.AddHandlers(m) privatechannel.AddHandlers(m) reply.AddHandlers(m) realtimeapi.AddHandlers(m) presenceapi.AddHandlers(m) slackapi.AddHandlers(m, c) credential.AddHandlers(m, r.Log, c) emailapi.AddHandlers(m) mmdb, err := helper.ReadGeoIPDB(c) if err != nil { r.Log.Critical("ip persisting wont work err: %s", err.Error()) } else { defer mmdb.Close() } // set default values for dev env if r.Conf.Environment == "dev" { go setDefaults(r.Log) } payment.Initialize(c) m.Listen() // shutdown server defer m.Close() r.Listen() r.Wait() }