From 2784b0e70e7adcb99fc09d39a63020488f33eeb8 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Fri, 21 Oct 2022 03:04:05 +0400 Subject: [PATCH] Moved justcaptcha package. Added a comment for CheckCaptcha() func. --- pkg/justcaptcha/justcaptcha.go | 20 ++++++++++++++++ pkg/server/justcaptcha/justcaptcha.go | 33 --------------------------- 2 files changed, 20 insertions(+), 33 deletions(-) create mode 100644 pkg/justcaptcha/justcaptcha.go delete mode 100644 pkg/server/justcaptcha/justcaptcha.go diff --git a/pkg/justcaptcha/justcaptcha.go b/pkg/justcaptcha/justcaptcha.go new file mode 100644 index 0000000..c3ff987 --- /dev/null +++ b/pkg/justcaptcha/justcaptcha.go @@ -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 +} diff --git a/pkg/server/justcaptcha/justcaptcha.go b/pkg/server/justcaptcha/justcaptcha.go deleted file mode 100644 index db4f7fb..0000000 --- a/pkg/server/justcaptcha/justcaptcha.go +++ /dev/null @@ -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 -}