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 :)") } }
func imageProcessing(c *gin.Context) { client, _ := gosseract.NewClient() file, header, err := c.Request.FormFile("file") file_path := "./tmp/" + header.Filename image, err := os.Create(file_path) if err != nil { log.Fatal(err) } defer image.Close() _, err = io.Copy(image, file) if err != nil { log.Fatal(err) } out, _ := client.Src(file_path).Out() out = stringProcessing(out) c.String(http.StatusOK, out) }
func home(c *gin.Context) { c.String(http.StatusOK, "Ok") }