1
0
justguestbook/pkg/server/justcaptcha/justcaptcha.go

34 lines
531 B
Go
Raw Normal View History

2022-10-19 03:25:43 +04:00
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
}