-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (35 loc) · 1.17 KB
/
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
package main
import (
"github.com/go-redis/redis/v8"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cache"
"github.com/gofiber/fiber/v2/middleware/favicon"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/monitor"
"github.com/gofiber/fiber/v2/middleware/recover"
"infura-test/endpoints"
"infura-test/utils"
"log"
"os"
"time"
)
func initRedis() {
var dbAddress = os.Getenv("REDIS_DB_ADDRESS")
if dbAddress == "" {
dbAddress = "localhost:6379"
}
utils.RDB = redis.NewClient(&redis.Options{Addr: dbAddress, Password: "", DB: 0})
}
func main() {
initRedis()
app := fiber.New(fiber.Config{})
app.Use(favicon.New())
app.Use(logger.New(logger.Config{Format: "[${time}] ${status} - ${latency} ${method} ${path}\n"}))
app.Use(recover.New()) // Used for handling Go panic()
app.Get("/monitor", monitor.New()) // Visual tool for api performance
// How's this caching layer compared to the redis one?
// Details in ./report/Report.mdx
app.Use(cache.New(cache.Config{Expiration: 10 * time.Second}))
app.Get("/:method", endpoints.InfuraHttpRequest)
log.Fatal(app.Listen(":" + os.Getenv("PORT")))
}