updated ipbl
Some checks reported errors
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build was killed

This commit is contained in:
Paul 2021-12-29 14:18:27 +01:00
parent 62bfead182
commit 26363d33bb

View File

@ -30,6 +30,7 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) {
})
e.POST("/ip", func(c echo.Context) (err error) {
var ip = new(models.IP)
var msg string
err = c.Bind(ip)
if err != nil {
return JSONResult(c, fmt.Errorf("Error when parsing body"), "")
@ -38,8 +39,9 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) {
if err != nil {
return JSONResult(c, fmt.Errorf("Error inserting data"), "")
}
var msg = fmt.Sprintf("Inserted %d IP", num)
log.Println(msg)
if num > 0 {
msg = fmt.Sprintf("Inserted %d IP", num)
}
return c.JSON(http.StatusOK, msg)
})
e.GET("/ips", func(c echo.Context) (err error) {
@ -52,12 +54,15 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) {
})
e.POST("/ips", func(c echo.Context) (err error) {
var ips = []models.IP{}
var msg string
err = c.Bind(&ips)
if err != nil {
return c.JSON(http.StatusInternalServerError, "Error when parsing body")
}
numinsert, numfail, _ := models.InsertIPBulk(cfg, &ips)
msg := fmt.Sprintf("Inserted %d IP, %d errors", numinsert, numfail)
numinsert, _, _ := models.InsertIPBulk(cfg, &ips)
if numinsert > 0 {
msg = fmt.Sprintf("Inserted %d IP", numinsert)
}
log.Println(msg)
return c.JSON(http.StatusOK, msg)
})