Skip to content

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.

License

Notifications You must be signed in to change notification settings

pcpratheesh/ip-guard-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

    import (
        guard "github.com/pcpratheesh/ip-guard-middleware/middleware/gin"
    )

Initializing the options

var opts = []options.Options{
    options.WithWhiteListIPs([]string{
        "your-ip",
    }),
}

Custom fallback handler function

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

About

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages