Created
September 27, 2019 14:21
-
-
Save LouisHrg/5a318179f40c3692b021bc5f2e527ae0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package middleware | |
import ( | |
"net/http" | |
"github.com/gin-gonic/gin" | |
"github.com/go-vote/provider" | |
"github.com/go-vote/model" | |
) | |
// IPFirewall : block banned IPs | |
func IPFirewall() gin.HandlerFunc { | |
var db = provider.GetDB() | |
var blocked model.Ip | |
return func(c *gin.Context) { | |
if !db.Where("address = ?", c.ClientIP()).Find(&blocked).RecordNotFound() { | |
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{ | |
"status": http.StatusForbidden, | |
"message": "Permission denied", | |
}) | |
return | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment