-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapi.go
55 lines (45 loc) · 1.16 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"log"
"net/http"
"github.com/databr/api/config"
"github.com/databr/api/database"
"github.com/databr/api/middleware"
"github.com/databr/api/service"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.Use(gin.Logger())
r.Use(gin.Recovery())
r.Use(middleware.CORS())
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.AbortWithStatus(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)
}