go get -u github.com/PrivateCaptcha/private-captcha-go
Add import:
import pc "github.com/PrivateCaptcha/private-captcha-go"
Create the client:
client, err := pc.NewClient(pc.Configuration{APIKey: "pc_abcdef"})
// ... handle err
Configuration
object allows to switch to EU endpoint, specify default form field for the solution, HTTP client, and status code for middleware version.
Verify()
supports automatic backoff and retrying (configured via VerifyInput
parameter), enabled by default. You need to check the captcha verification status yourself.
output, err := client.Verify(ctx, pc.VerifyInput{Solution: solution})
// ... handle err
if !output.Success {
fmt.Printf("Captcha verification failed. Error: %s", result.Error())
}
VerifyRequest()
operates on the http.Request
level, extracts and verifies form field, configured via Configuration
object for the client instance, with standard defaults. You only need to check if the err == nil
.
func handler(w http.ResponseWriter, r *http.Request) {
if err := client.VerifyRequest(r.Context(), r); err != nil {
return
}
}
VerifyFunc()
is a basic HTTP middleware that returns http.StatusForbidden
(configured via Configuration
object for client instance) if the captcha solution is not verified.
mux.Handle("POST /my/form", client.VerifyFunc(actualHandler))
input := pc.Configuration{
Solution: "solution",
MaxBackoffSeconds: 10,
Attempts: 10,
}
output, err := client.Verify(ctx, input)
// ... handle err
This project is licensed under the MIT License - see the LICENSE file for details.
For issues with this Go client, please open an issue on GitHub.
For Private Captcha service questions, visit privatecaptcha.com.