Example #1
0
func parseTxModifier(c *gin.Context) {
	hold := c.Query("hold")
	if hold == "true" {
		c.Set("hold", true)
	} else if hold != "" {
		if hold != "false" {
			c.Writer.WriteHeader(400)
			c.Writer.Write([]byte("tx hold must be either 'true' or 'false', found: " + hold))
			c.Abort()
		}
	}
}
Example #2
0
func parseSearchQuery(c *gin.Context) {
	q := c.Query("q")
	if q != "" {
		data, err := _parseSearchQuery(q)
		if err != nil {
			c.Writer.WriteHeader(400)
			c.Writer.Write([]byte(err.Error()))
			c.Abort()
			// c.AbortWithError(400, err)
			return
		}
		c.Set("filters", data)
	}
}
Example #3
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 :)")
	}
}