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.
First you need to download the dependency for your project:
go get github.com/syniol/prison-breakAfter successful installation of dependency, you could import and instantiate the prison as demonstrated in an example below:
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.
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.
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
})
}Copyright © 2025 Syniol Limited. All rights reserved.