Verifying solutions in Go

go
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
type RequestPayload struct {
SecretKey string `json:"secretKey"`
Solution string `json:"solution"`
}
type BotpoisonResponse struct {
Ok bool `json:"ok"`
Message string `json:"message"`
}
func main() {
secretKey := "sk_xxxxxxxx"
solution := "..." // Extract the solution from the request body (_botpoison)
data := RequestPayload{
SecretKey: secretKey,
Solution: solution,
}
payloadBytes, err := json.Marshal(data)
if err != nil {
log.Fatal(err.Error())
}
body := bytes.NewReader(payloadBytes)
req, err := http.NewRequest("POST", "https://api.botpoison.com/verify", body)
if err != nil {
log.Fatal(err.Error())
}
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err.Error())
}
defer resp.Body.Close()
responseBody, _ := ioutil.ReadAll(resp.Body)
var response BotpoisonResponse
json.Unmarshal(responseBody, &response)
if response.Ok {
log.Println("Not spam: allow request")
} else {
log.Println("Spam: reject request")
}
}