-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
36 lines (32 loc) · 915 Bytes
/
main.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
package main
import (
"time"
"github.com/carlosvin/covid-rest-go/repo"
"github.com/carlosvin/covid-rest-go/handlers"
"github.com/carlosvin/covid-rest-go/readers"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func main() {
repository := repo.NewRepo(readers.NewReaderFactory())
router := handlers.NewRouter(repository)
err := repository.Fetch()
if err != nil {
panic(err)
}
repository.Watch(time.Hour)
r := gin.Default()
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"*"},
AllowMethods: []string{"GET"},
AllowHeaders: []string{"Origin"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: false,
MaxAge: 12 * time.Hour,
}))
r.GET("/countries", router.Countries)
r.GET("/countries/:code", router.Country)
r.GET("/countries/:code/dates", router.CountryDates)
r.GET("/countries/:code/dates/:date", router.CountryDate)
r.Run()
}