Exemplo n.º 1
0
func rateLimit(c *gin.Context) {

	ip := c.ClientIP()
	value := int(ips.Add(ip, 1))
	if value%50 == 0 {
		fmt.Printf("ip: %s, count: %d\n", ip, value)
	}
	if value >= 200 {
		if value%200 == 0 {
			fmt.Println("ip blocked")
		}
		c.Abort()
		c.String(503, "you were automatically banned :)")
	}
}
Exemplo n.º 2
0
// Used to enable log15 logging instead of the default Gin logging.
// This is done mainly because we at Eris uses log15 in other components.
func logHandler(c *gin.Context) {

	path := c.Request.URL.Path

	// Process request
	c.Next()

	clientIP := c.ClientIP()
	method := c.Request.Method
	statusCode := c.Writer.Status()
	comment := c.Errors.String()

	log.Info("[GIN] HTTP: "+clientIP, "Code", statusCode, "Method", method, "path", path, "error", comment)

}