Exemplo n.º 1
0
// TODO(cihangir): make generalized "withTestServer"
func withTestServer(t *testing.T, f func(url string)) {
	const workerName = "paymentwebhook"

	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()

	payment.Initialize(c)

	port := tests.GetFreePort()
	mc := mux.NewConfig(workerName, "localhost", port)
	mc.Debug = r.Conf.Debug
	if r.Conf.Debug {
		stripe.LogLevel = 3
	}
	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()
}
Exemplo n.º 2
0
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()
}