Skip to content
A package for handling reCaptcha (http://www.google.com/recaptcha) form submissions in Go (http://golang.org/).
Go
Branch: master
Clone or download
Pull request Compare This branch is 2 commits ahead of dpapathanasiou:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
recaptchatest
.gitignore
.travis.yml
LICENSE
README.md
go.mod
go.sum
recaptcha.go
recaptcha_test.go

README.md

go-recaptcha

Build Status Go Report Card GoDoc

About

This package handles reCAPTCHA (API versions 2 and 3) form submissions in Go.

Usage

Import the package:

import "github.com/tekkamanendless/go-recaptcha"

Create a new reCAPTCHA verifier.

recaptchaVerifier := recaptcha.New("YOUR_PRIVATE_KEY")

Verify a token.

success, err := recaptchaVerifier.Verify("SOME_RECAPTCHA_RESPONSE_TOKEN")

Or verify with a client IP address, too:

success, err := recaptchaVerifier.VerifyRemoteIP(clientIpAddress, "SOME_RECAPTCHA_RESPONSE_TOKEN")

This workflow supports both reCAPTCHA v2 and reCAPTCHA v3.

Testing

You may use the included recaptchatest package to create a reCAPTCHA server suitable for unit testing.

import "github.com/tekkamanendless/go-recaptcha/recaptchatest"
// Create a new reCAPTCHA test server.
testServer := recaptchatest.NewServer()
defer testServer.Close()

// Create a new site.
site := testServer.NewSite()

// Create your reCAPTCHA verifier normally.
recaptchaVerifier := recaptcha.New(site.PrivateKey)

// Override the endpoint.
recaptchaVerifier.VerifyEndpoint = testServer.VerifyEndpoint()

// Generate a response token from the site.
token := site.NewResponseToken()

// Verify the token normally.
success, err := recaptchaVerifier.Verify(token)
You can’t perform that action at this time.