-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
44 lines (37 loc) · 1002 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
37
38
39
40
41
42
43
44
package main
import (
"github.com/gin-gonic/gin"
"github.com/marc7806/notion-cache/cache"
"github.com/marc7806/notion-cache/database"
"github.com/marc7806/notion-cache/metrics"
"github.com/marc7806/notion-cache/routes"
"github.com/marc7806/notion-cache/scheduler"
"log"
)
var (
router = gin.Default()
)
func main() {
// todo: add api-token middleware for authentication
// initialize database
datastore, err := database.InitMongoDataStore()
if err != nil {
panic(err)
}
// disconnect database client once application shuts down
defer database.DisconnectDb(datastore)
// initialize caching metadata store
cache.InitCache()
// init caching scheduler to be run in defined interval
go scheduler.InitScheduler()
// register metrics endpoint and middlewares
metrics.RegisterMetrics(router)
buildRoutes()
log.Println("Listening on port 8080...")
router.Run(":8080")
}
func buildRoutes() {
api := router.Group("/v1")
routes.AddCacheRoutes(api)
routes.AddNotionRoutes(api)
}