-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (48 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cache"
"github.com/gofiber/fiber/v2/middleware/compress"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/limiter"
_ "github.com/jinzhu/gorm/dialects/postgres"
"golang_auth/database"
"golang_auth/routes"
"log"
"time"
)
func main() {
//INITIALIZE APP
app := fiber.New()
//USE CORS
app.Use(cors.New())
//DATABASE CONFIG
database.ConnectDB()
//SETUP ROUTES
routes.SetupApiRoutes(app)
//CACHE
app.Use(cache.New(cache.Config{Next: func(c *fiber.Ctx) bool {
return c.Query("refresh") == "true"
},
Expiration: 30 * time.Minute,
CacheControl: true,
}))
//RATE LIMITER
app.Use(limiter.New(limiter.Config{
Max: 5,
Expiration: 10 * time.Second,
KeyGenerator: func(ctx *fiber.Ctx) string {
return ctx.IP()
},
LimitReached: func(ctx *fiber.Ctx) error {
return ctx.SendStatus(fiber.StatusTooManyRequests)
},
}))
//COMPRESSIONS
app.Use(compress.New(compress.Config{Level: compress.LevelBestSpeed}))
//404 NOT FOUND
app.Use(func(c *fiber.Ctx) error {
return c.SendStatus(400)
})
log.Fatal(app.Listen(":3000"))
}