aboutsummaryrefslogtreecommitdiff
path: root/util/blacklist.go
diff options
context:
space:
mode:
authorFChannel <>2022-05-08 14:57:40 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commit580dec5b89215310ce34341e11ff17fe38bdb63a (patch)
tree894424df66a9d9f7e41805822f29adac8fb490fe /util/blacklist.go
parentf7bf818d29393ceaccf4d2906557351fa6a4f49f (diff)
more cleanup, logging and error logging everywhere
things are mostly in place can work on "features" and polish
Diffstat (limited to 'util/blacklist.go')
-rw-r--r--util/blacklist.go33
1 files changed, 14 insertions, 19 deletions
diff --git a/util/blacklist.go b/util/blacklist.go
index 5368037..acb0b21 100644
--- a/util/blacklist.go
+++ b/util/blacklist.go
@@ -11,28 +11,28 @@ type PostBlacklist struct {
Regex string
}
-func DeleteRegexBlacklistDB(id int) error {
+func DeleteRegexBlacklist(id int) error {
query := `delete from postblacklist where id=$1`
-
_, err := config.DB.Exec(query, id)
- return err
+
+ return MakeError(err, "DeleteRegexBlacklist")
}
-func GetRegexBlacklistDB() ([]PostBlacklist, error) {
+func GetRegexBlacklist() ([]PostBlacklist, error) {
var list []PostBlacklist
query := `select id, regex from postblacklist`
-
rows, err := config.DB.Query(query)
+
if err != nil {
- return list, err
+ return list, MakeError(err, "GetRegexBlacklist")
}
defer rows.Close()
for rows.Next() {
var temp PostBlacklist
- rows.Scan(&temp.Id, &temp.Regex)
+ rows.Scan(&temp.Id, &temp.Regex)
list = append(list, temp)
}
@@ -40,10 +40,10 @@ func GetRegexBlacklistDB() ([]PostBlacklist, error) {
}
func IsPostBlacklist(comment string) (bool, error) {
- postblacklist, err := GetRegexBlacklistDB()
+ postblacklist, err := GetRegexBlacklist()
if err != nil {
- return false, err
+ return false, MakeError(err, "IsPostBlacklist")
}
for _, e := range postblacklist {
@@ -57,20 +57,15 @@ func IsPostBlacklist(comment string) (bool, error) {
return false, nil
}
-func WriteRegexBlacklistDB(regex string) error {
+func WriteRegexBlacklist(regex string) error {
var re string
query := `select from postblacklist where regex=$1`
if err := config.DB.QueryRow(query, regex).Scan(&re); err != nil {
- return err
- }
-
- if re != "" {
- return nil
+ query = `insert into postblacklist (regex) values ($1)`
+ _, err := config.DB.Exec(query, regex)
+ return MakeError(err, "WriteRegexBlacklist")
}
- query = `insert into postblacklist (regex) values ($1)`
-
- _, err := config.DB.Exec(query, regex)
- return err
+ return nil
}