https://github.com/syniol/prison-break
Go (Golang) Library to imprison or block spam request using built-in memory
https://github.com/syniol/prison-break
Last synced: 9 months ago
JSON representation
Go (Golang) Library to imprison or block spam request using built-in memory
- Host: GitHub
- URL: https://github.com/syniol/prison-break
- Owner: syniol
- License: apache-2.0
- Created: 2025-09-05T00:09:52.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-09-05T00:19:10.000Z (10 months ago)
- Last Synced: 2025-09-05T02:26:43.006Z (10 months ago)
- Language: Go
- Size: 6.84 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Prison Break (Stateless DDOS Detection & Prevention)
 
Official Mascot for Prison Break Library. Generated by Adobe AI and Imagined by Syniol Limited
Banning IP Addresses trying to spam your K8S pods and linux containers. It could be implemented as part of request handler for
your RESTful.
## Quickstart Guide
First you need to download the dependency for your project:
```shell
go get github.com/syniol/prison-break
```
After successful installation of dependency, you could import and instantiate the prison as demonstrated in an example below:
```go
package main
import (
"context"
"time"
prisonbreak "github.com/syniol/prison-break"
)
func main() {
// Instantiating a new prison with default Rules (Configuration) and no Context to signal cancellation
prison := prisonbreak.NewPrison(nil, nil)
// Instantiating a new prison with default Rules (Configuration) and Context to signal cancellation
prison := prisonbreak.NewPrison(context.Background(), nil)
// Instantiating a new prison with custom Rules (Configuration) and Context to signal cancellation
prison := prisonbreak.NewPrison(
context.Background(),
&prisonbreak.PrisonRules{
IsolationRedLineStrikeCount: 20,
IsolationRedLineDuration: time.Nanosecond * 10,
PrisonBreakDuration: time.Nanosecond * 35,
},
)
}
```
By calling `IsIsolated` method for an IP address, we initially add this in a memory or if the IP
exists we will increment the StrikeCount for the prisoner.
```go
package main
import (
"context"
"time"
prisonbreak "github.com/syniol/prison-break"
)
func main() {
prison := prisonbreak.NewPrison(nil, nil)
var isIsolated bool = prison.IsIsolated("127.0.0.1")
if isIsolated {
// do something
}
}
```
You could also execute `Torture` for an IP with an action method call. This will run `IsIsolated`
under the hood, but it omits the responsibility of creating a condition. `func () error`.
```go
package main
import (
"context"
"time"
prisonbreak "github.com/syniol/prison-break"
)
func main() {
prison := prisonbreak.NewPrison(nil, nil)
prison.Torture("127.0.0.1", func () error {
// do something
return nil
})
}
```
#### Credits
Copyright © 2025 Syniol Limited. All rights reserved.