Fiberpow is a Fiber middleware, it aims to block (or at least slow down) bots, by periodically asking clients for a proof of work challenge.
int
Maximum number of calculated hashes by the client, default: 30000.
time.Duration
Interval between challenges for the same IP.
func(c *fiber.Ctx) bool
Use this if you need to skip the PoW challenge in certain conditions, true equals skip.
fiber.Storage
Database used to keep track of challenges, for reference use https://github.com/gofiber/storage.
go get github.com/witer33/fiberpow
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/storage/redis/v3"
"github.com/witer33/fiberpow"
)
func main() {
app := fiber.New()
app.Use(fiberpow.New(fiberpow.Config{
Storage: redis.New(),
}))
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello World")
})
app.Listen(":3000")
}
import (
"time"
"github.com/gofiber/fiber/v2"
"github.com/witer33/fiberpow"
"github.com/gofiber/storage/redis/v3"
)
func main() {
app := fiber.New()
app.Use(fiberpow.New(fiberpow.Config{
PowInterval: 10 * time.Minute,
Difficulty: 60000,
Filter: func(c *fiber.Ctx) bool {
return c.IP() == "127.0.0.1"
},
Storage: redis.New(),
}))
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello World")
})
app.Listen(":3000")
}