snow/aid/fiber.go

34 lines
739 B
Go
Raw Normal View History

package aid
import (
2024-01-20 01:58:57 +00:00
"strings"
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/limiter"
"github.com/gofiber/fiber/v2/middleware/logger"
)
func FiberLogger() fiber.Handler {
return logger.New(logger.Config{
Format: "(${method}) (${status}) (${latency}) ${path}\n",
2024-01-20 01:58:57 +00:00
Next: func(c *fiber.Ctx) bool {
return strings.Contains(c.Path(), "//")
},
})
}
func FiberLimiter() fiber.Handler {
return limiter.New(limiter.Config{
Max: 100,
Expiration: 1 * time.Minute,
})
}
func FiberCors() fiber.Handler {
return cors.New(cors.Config{
AllowOrigins: "*",
AllowHeaders: "Origin, Content-Type, Accept, Authorization, X-Requested-With",
})
}