func withTestServer(t *testing.T, f func(url string)) { const workerName = "pingtest" r := runner.New(workerName) if err := r.Init(); err != nil { t.Fatal(err) } c := config.MustRead(r.Conf.Path) // init mongo connection modelhelper.Initialize(c.Mongo) defer modelhelper.Close() port := tests.GetFreePort() mc := mux.NewConfig(workerName, "localhost", port) mc.Debug = r.Conf.Debug m := mux.New(mc, r.Log, r.Metrics) AddHandlers(m) m.Listen() go r.Listen() f(fmt.Sprintf("http://localhost:%s", port)) if err := r.Close(); err != nil { t.Fatalf("server close errored: %s", err.Error()) } // shutdown server m.Close() }
func main() { r := runner.New(Name) if err := r.Init(); err != nil { fmt.Println(err) return } appConfig := config.MustRead(r.Conf.Path) modelhelper.Initialize(appConfig.Mongo) defer modelhelper.Close() // create a realtime service provider instance. pubnub := models.NewPubNub(appConfig.GateKeeper.Pubnub, r.Log) defer pubnub.Close() mc := mux.NewConfig(Name, appConfig.GateKeeper.Host, appConfig.GateKeeper.Port) m := mux.New(mc, r.Log, r.Metrics) h := api.NewHandler(pubnub, appConfig, r.Log) h.AddHandlers(m) // consume messages from RMQ // Gatekeeper is not using RMQ, but runner is creating a message queue for // each worker. We need to discard the messages in the queue, otherwise // all the messages are piled up go r.Listen() m.Listen() defer m.Close() 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() }