diff --git a/src/routers/funcs.go b/src/routers/funcs.go index 2a4fd83..7d67d00 100644 --- a/src/routers/funcs.go +++ b/src/routers/funcs.go @@ -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) })