snow/aid/fiber.go

31 lines
731 B
Go
Raw Normal View History

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{
2023-11-05 02:43:21 +00:00
Format: "(${status}) (${latency}) ${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()
}
}