File: comment_check.go

package info (click to toggle)
golang-github-adtac-go-akismet 0.0~git20181220.0ca9e10-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 104 kB
  • sloc: makefile: 2
file content (24 lines) | stat: -rw-r--r-- 593 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package akismet

import (
	"errors"
)

// This function checks whether a particular Comment is spam or not by querying
// the Akismet API. The returned boolean is true if the comment was classified
// as spam, false otherwise. If the request failed for whatever reason, the
// error returned will be non-nil.
func Check(c *Comment, key string) (bool, error) {
	respBody, err := postRequest(c, key, "comment-check")
	if err != nil {
		return true, err
	}

	if respBody == "true" {
		return true, nil
	} else if respBody == "false" {
		return false, nil
	}

	return true, errors.New(respBody)
}