An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

Prison Break (Stateless DDOS Detection & Prevention)

![workflow](https://github.com/syniol/prison-break/actions/workflows/pipeline.yml/badge.svg) ![workflow](https://github.com/syniol/prison-break/actions/workflows/release.yml/badge.svg)


Go (Golang) Gopher Mascot

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.