delete.go 701 B

12345678910111213141516171819202122232425262728293031
  1. package sqlite
  2. import (
  3. "fmt"
  4. "github.com/crowdsecurity/crowdsec/pkg/types"
  5. log "github.com/sirupsen/logrus"
  6. )
  7. /*try to delete entries with matching fields */
  8. func (c *Context) DeleteBan(target string) (int, error) {
  9. if target != "" {
  10. ret := c.Db.Delete(types.BanApplication{}, "ip_text = ?", target)
  11. if ret.Error != nil {
  12. log.Errorf("Failed to delete record with BanTarget %s : %v", target, ret.Error)
  13. return 0, ret.Error
  14. }
  15. return int(ret.RowsAffected), nil
  16. }
  17. return 0, fmt.Errorf("no target provided")
  18. }
  19. func (c *Context) DeleteAll() error {
  20. allBa := types.BanApplication{}
  21. records := c.Db.Delete(&allBa)
  22. if records.Error != nil {
  23. return records.Error
  24. }
  25. return nil
  26. }