https://github.com/pcpratheesh/ip-guard-middleware
IP access control middleware for Gin, echo and fiber web frameworks. This middleware enhances your application's security by allowing you to define a whitelist of permitted IP addresses while providing extended features for handling non-whitelisted IPs.
https://github.com/pcpratheesh/ip-guard-middleware
Last synced: 2 months ago
JSON representation
IP access control middleware for Gin, echo and fiber web frameworks. This middleware enhances your application's security by allowing you to define a whitelist of permitted IP addresses while providing extended features for handling non-whitelisted IPs.
- Host: GitHub
- URL: https://github.com/pcpratheesh/ip-guard-middleware
- Owner: pcpratheesh
- License: mit
- Created: 2023-08-14T07:57:18.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-14T15:17:12.000Z (almost 3 years ago)
- Last Synced: 2025-05-30T00:41:38.274Z (about 1 year ago)
- Language: Go
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ip-guard-middleware
IP access control middleware for Gin, echo and fiber web frameworks. This middleware enhances your application's security by allowing you to define a whitelist of permitted IP addresses while providing extended features for handling non-whitelisted IPs.
## Installation
To install GoHealthWatch, use the following command:
```
go get github.com/pcpratheesh/ip-guard-middleware/
```
## Usage
### For Gin
*Import the package*
```go
import (
guard "github.com/pcpratheesh/ip-guard-middleware/middleware/gin"
)
```
*Initializing the options*
```go
var opts = []options.Options{
options.WithWhiteListIPs([]string{
"your-ip",
}),
}
```
*Custom fallback handler function*
```go
var fallbackHandler = func(ctx *gin.Context, clientIP string) {
ctx.JSON(http.StatusForbidden, map[string]string{
"message": "Not allowed to access.",
})
ctx.Abort()
return
}
...
options.SetFallbackHandler(
options.GinFallbackHandler(fallbackHandler),
)
```
## Examples
- [Gin](example/gin/main.go)
- [Echo](example/echo/main.go)
- [Fiber](example/fiber/main.go)