示例#1
0
文件: routes.go 项目: kimquy/go-image
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 :)")
	}
}
示例#2
0
文件: main.go 项目: kimquy/go-image
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)
}
示例#3
0
文件: main.go 项目: kimquy/go-image
func home(c *gin.Context) {
	c.String(http.StatusOK, "Ok")
}