1
0
Fork 0

Moved justcaptcha package. Added a comment for CheckCaptcha() func.

This commit is contained in:
Alexander Andreev 2022-10-21 03:04:05 +04:00
parent 6aa2bd10ff
commit 2784b0e70e
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F
2 changed files with 20 additions and 33 deletions

View File

@ -0,0 +1,20 @@
package justcaptcha
import (
"net/http"
"net/url"
)
// CheckCaptcha performs a request to a justcaptcha service and returns wether
// CAPTCHA was solved or not. If there is a problem with connection to the
// service it will return an error.
func CheckCaptcha(id string, serviceURL string) (bool, error) {
path, _ := url.JoinPath(serviceURL, id)
r, err := http.Get(path)
if err != nil {
return false, err
}
return r.StatusCode == 202, nil
}

View File

@ -1,33 +0,0 @@
package justcaptcha
import (
"context"
"net"
"net/http"
"strings"
)
func CheckCaptcha(id string, url string) (bool, error) {
var c http.Client
var r *http.Response
var err error
if strings.Contains(url, ":") {
c = http.Client{}
} else {
c = http.Client{
Transport: &http.Transport{
DialContext: func(_ context.Context, _, addr string) (net.Conn, error) {
return net.Dial("unix", addr)
},
},
}
}
r, err = c.Get(url)
if err != nil {
return false, err
}
return r.StatusCode == 200, nil
}