https://github.com/sj14/recaptcha
✔️ Handle reCAPTCHA v2 and v3 with Go
https://github.com/sj14/recaptcha
go golang recaptcha recaptcha-v2 recaptcha-v3
Last synced: 30 days ago
JSON representation
✔️ Handle reCAPTCHA v2 and v3 with Go
- Host: GitHub
- URL: https://github.com/sj14/recaptcha
- Owner: sj14
- License: mit
- Created: 2020-03-21T15:43:38.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-21T19:02:43.000Z (almost 6 years ago)
- Last Synced: 2025-04-02T04:50:30.854Z (10 months ago)
- Topics: go, golang, recaptcha, recaptcha-v2, recaptcha-v3
- Language: Go
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# reCAPTCHA for Go
[](https://pkg.go.dev/github.com/sj14/recaptcha?tab=doc)
[](https://goreportcard.com/report/github.com/sj14/recaptcha)

## Installation
```bash
go get -u github.com/sj14/recaptcha
```
## Usage
The result will always return an error when any kind of failure occured, thus only checking the error is sufficient.
### reCAPTCHA v2
See [reCAPTCHA v2 docs](https://developers.google.com/recaptcha/docs/display)
#### HTML
```html
```
#### Go
```go
result, err := recaptcha.VerifyV2(recaptchaSecret, httpRequest)
if err != nil {
log.Fatalf("recaptcha failed: %v\n", err)
}
// result is not necessary to check, only required for more details
```
### reCAPTCHA v3
See [reCAPTCHA v3 docs](https://developers.google.com/recaptcha/docs/v3)
#### HTML
```html
grecaptcha.ready(function () {
grecaptcha.execute('<YOUR_SITE_KEY>', { action: 'register' }).then(function (token) {
var recaptchaResponse = document.getElementById('g-recaptcha-response');
recaptchaResponse.value = token;
});
});
```
#### Go
Without options:
```go
result, err := recaptcha.VerifyV3(recaptchaSecret, httpRequest)
if err != nil {
log.Fatalf("recaptcha failed: %v\n", err)
}
// result is not necessary to check, only required for more details
```
With options:
```go
// The default action is empty ("") and thus not checked.
// The default minimum required score is 0.5
result, err := recaptcha.VerifyV3(recaptchaSecret, httpRequest, recaptcha.Action("register"), recaptcha.MinScore(0.7))
if err != nil {
log.Fatalf("recaptcha failed: %v\n", err)
}
// result is not necessary to check, only required for more details
```
## Shoulders
This package is based on the work of [Adam Ng](https://www.socketloop.com/tutorials/golang-recaptcha-example) and I highly support his appeal:
> IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.