func TestMain(m *testing.M) {
	session, err := mgo.Dial(miscs.GlobalConfig.MongoDB.URL)
	defer session.Close()
	if err != nil {
		os.Exit(1)
	}
	model.InitDB(session.DB(miscs.GlobalConfig.MongoDB.DBName))
	miscs.InitConfig(os.Getenv("GOPATH") + "/src/github.com/realglobe-Inc/edo-xrs/conf/app.conf")

	code := m.Run()
	os.Exit(code)
}
Exemple #2
0
func main() {
	// start pprof (system profiler) server
	//go func() {
	//	logger.Info(http.ListenAndServe("localhost:6000", nil))
	//}()

	// start routing
	session, err := mgo.Dial(miscs.GlobalConfig.MongoDB.URL)
	defer session.Close()
	if err != nil {
		logger.Err(err)
		os.Exit(1)
	}
	model.InitDB(session.DB(miscs.GlobalConfig.MongoDB.DBName))

	c := controller.New(session)

	router := martini.Classic()
	router.Get("/", func() string { return "Welcome to xRS API Server." })

	// CROS support
	router.Options("**", func(params martini.Params, w http.ResponseWriter) {
		w.Header().Set("Content-Type", "application/json; charset=utf-8")
		w.Header().Set("Access-Control-Allow-Origin", "*")
		w.Header().Set("Access-Control-Allow-Headers", "X-Experience-API-Version")
	})
	router.Get("/:user/:app/about", func(params martini.Params, w http.ResponseWriter) (int, string) {
		w.Header().Set("Content-Type", "application/json; charset=utf-8")
		w.Header().Set("Access-Control-Allow-Origin", "*")
		w.Header().Set("Access-Control-Allow-Headers", "X-Experience-API-Version")

		return http.StatusOK, `{"version": ["1.0.0", "1.0.1", "1.0.2"]}`
	})
	router.Put("/:user/:app/statements", c.StoreStatement)
	router.Post("/:user/:app/statements", c.StoreMultStatement)
	router.Head("/:user/:app/statements", c.FindStatementHead)
	router.Get("/:user/:app/statements", acceptlang.Languages(), c.FindStatement)

	router.Run()
}