31 lines
716 B
Go
31 lines
716 B
Go
|
package aid
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
|
||
|
"github.com/gofiber/fiber/v2"
|
||
|
"github.com/gofiber/fiber/v2/middleware/limiter"
|
||
|
"github.com/gofiber/fiber/v2/middleware/logger"
|
||
|
)
|
||
|
|
||
|
func FiberLogger() fiber.Handler {
|
||
|
return logger.New(logger.Config{
|
||
|
Format: "${status} ${path}\n",
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func FiberLimiter() fiber.Handler {
|
||
|
return limiter.New(limiter.Config{
|
||
|
Max: 100,
|
||
|
Expiration: 1 * time.Minute,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func FiberCors() fiber.Handler {
|
||
|
return func(c *fiber.Ctx) error {
|
||
|
c.Set("Access-Control-Allow-Origin", "*")
|
||
|
c.Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
||
|
c.Set("Access-Control-Allow-Headers", "Content-Type, Authorization, Origin, Accept, X-Requested-With")
|
||
|
return c.Next()
|
||
|
}
|
||
|
}
|