Esempio n. 1
0
File: api.go Progetto: zannet/api
func main() {
	r := gin.Default()
	r.Use(gin.Logger())
	r.Use(gin.Recovery())
	r.Use(middleware.CORS())
	// r.Use(middleware.Authentication())
	r.Use(middleware.Analytics())
	r.Use(middleware.StatusPageIO())

	if config.Env == "production" {
		r.Use(middleware.NewRelic())
		middleware.InitNewrelicAgent(config.NewRelicLicense, config.NewRelicAppName, true)
	}

	databaseDB := database.NewMongoDB()

	parliamentarians := service.ParliamentariansService{r}
	parties := service.PartiesService{r}
	states := service.StatesService{r}
	pingdom := service.PingdomService{r}
	doc := service.ApiDocumentationService{r}

	parliamentarians.Run(databaseDB)
	parties.Run(databaseDB)
	states.Run(databaseDB)
	pingdom.Run()
	doc.Run()

	r.OPTIONS("/*path", func(c *gin.Context) {
		c.Writer.Header().Set("Allow", "GET, OPTIONS")
		c.Abort(200)
	})

	r.GET("/", func(c *gin.Context) {
		http.Redirect(
			c.Writer,
			c.Request,
			"http://databr.io",
			302)
	})

	log.Println("Listening port", config.Port)
	r.Run(":" + config.Port)
}
Esempio n. 2
0
	var r *gin.Engine

	BeforeEach(func() {
		databaseDB = database.NewMongoDB("test")
		r = gin.Default()

		parliamentarians := service.ParliamentariansService{r}
		parliamentarians.Run(databaseDB)

		parties := service.PartiesService{r}
		parties.Run(databaseDB)

		states := service.StatesService{r}
		states.Run(databaseDB)

		pingdom := service.PingdomService{r}
		pingdom.Run()

		doc := service.ApiDocumentationService{r}
		doc.Run()

		recorder = httptest.NewRecorder()
	})

	AfterEach(func() {
		databaseDB.Current.DropDatabase()
	})

	Describe("GET /v1/parliamentarians", func() {
		BeforeEach(func() {
			request, _ = http.NewRequest("GET", "/v1/parliamentarians", nil)