-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.go
43 lines (35 loc) · 1.13 KB
/
server.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
package main
import (
"log"
"os"
"github.com/Pradumnasaraf/Contributors/config"
"github.com/Pradumnasaraf/Contributors/graph"
"github.com/Pradumnasaraf/Contributors/handler"
"github.com/Pradumnasaraf/Contributors/middleware"
"github.com/Pradumnasaraf/Contributors/mongo"
"github.com/Pradumnasaraf/Contributors/prometheus"
"github.com/Pradumnasaraf/Contributors/redis"
"github.com/gin-gonic/gin"
)
func main() {
// Config setup
config.Config()
// Database connection
redis.RedisInit()
mongoClient := mongo.MongoInit()
graph.GetMongoClient(mongoClient)
defer redis.RedisClose()
// Server setup
router := gin.Default()
// Bypasses Auth
router.Use(prometheus.RecordRequestLatency())
router.Use(prometheus.RequestMetricsMiddleware())
router.GET("/health", handler.HealthCheckHandler())
router.GET("/metrics", handler.PrometheusHandler())
router.Use(middleware.BasicAuthMiddleware())
router.Use(middleware.RedisRateLimiterMiddleware())
router.GET("/", handler.PlaygroundHandler())
router.POST("/query", handler.GraphqlHandler())
log.Printf("Server is running on http://localhost:%s", os.Getenv("PORT"))
log.Fatal(router.Run())
}