Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/witer33/fiberpow
https://github.com/witer33/fiberpow
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/witer33/fiberpow
- Owner: witer33
- License: apache-2.0
- Created: 2022-05-16T16:00:43.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-12T12:58:01.000Z (4 months ago)
- Last Synced: 2024-07-12T14:47:46.993Z (4 months ago)
- Language: Go
- Size: 93.8 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-fiber - witer33/fiberpow - Anti DDoS/Bot Middleware with a customizable Proof Of Work challenge. (⚙️ Middlewares / 🌱 Third Party)
README
# fiberpow
Fiberpow is a [Fiber](https://github.com/gofiber/fiber) middleware, it aims to block (or at least slow down) bots, by periodically asking clients for a proof of work challenge.
## Config explaination
#### Difficulty
```go
int
```
Maximum number of calculated hashes by the client, default: 30000.#### PowInterval
```go
time.Duration
```
Interval between challenges for the same IP.#### Filter
```go
func(c *fiber.Ctx) bool
```
Use this if you need to skip the PoW challenge in certain conditions, true equals skip.#### Storage
```go
fiber.Storage
```
Database used to keep track of challenges, for reference use https://github.com/gofiber/storage.## Installation
```
go get github.com/witer33/fiberpow
```
## Usage
### Basic config
```go
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")
}
```
### Custom config
```go
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")
}
```