Moved justcaptcha package. Added a comment for CheckCaptcha() func.
This commit is contained in:
parent
6aa2bd10ff
commit
2784b0e70e
20
pkg/justcaptcha/justcaptcha.go
Normal file
20
pkg/justcaptcha/justcaptcha.go
Normal 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
|
||||
}
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user