https://github.com/flamego/recaptcha
Package recaptcha is a middleware that provides reCAPTCHA integration for Flamego
https://github.com/flamego/recaptcha
captcha flamego go lsif-enabled middleware recaptcha-v2 recaptcha-v3
Last synced: 4 months ago
JSON representation
Package recaptcha is a middleware that provides reCAPTCHA integration for Flamego
- Host: GitHub
- URL: https://github.com/flamego/recaptcha
- Owner: flamego
- License: mit
- Created: 2021-05-22T08:02:30.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-08-03T17:51:53.000Z (10 months ago)
- Last Synced: 2025-08-03T19:33:21.994Z (10 months ago)
- Topics: captcha, flamego, go, lsif-enabled, middleware, recaptcha-v2, recaptcha-v3
- Language: Go
- Homepage:
- Size: 67.4 KB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# recaptcha
[](https://github.com/flamego/recaptcha/actions?query=workflow%3AGo)
[](https://pkg.go.dev/github.com/flamego/recaptcha?tab=doc)
Package recaptcha is a middleware that provides reCAPTCHA integration for [Flamego](https://github.com/flamego/flamego).
## Installation
```zsh
go get github.com/flamego/recaptcha
```
## Getting started
```html
function onSubmit(token) {
document.getElementById("demo-form").submit();
}
Submit
```
```go
package main
import (
"fmt"
"net/http"
"github.com/flamego/flamego"
"github.com/flamego/recaptcha"
"github.com/flamego/template"
)
func main() {
f := flamego.Classic()
f.Use(template.Templater())
f.Use(recaptcha.V3(
recaptcha.Options{
Secret: "",
VerifyURL: recaptcha.VerifyURLGoogle,
},
))
f.Get("/", func(t template.Template, data template.Data) {
data["SiteKey"] = ""
t.HTML(http.StatusOK, "home")
})
f.Post("/", func(w http.ResponseWriter, r *http.Request, re recaptcha.RecaptchaV3) {
token := r.PostFormValue("g-recaptcha-response")
resp, err := re.Verify(token)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte(err.Error()))
return
} else if !resp.Success {
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte(fmt.Sprintf("Verification failed, error codes %v", resp.ErrorCodes)))
return
}
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("Verified!"))
})
f.Run()
}
```
## Getting help
- Read [documentation and examples](https://flamego.dev/middleware/recaptcha.html).
- Please [file an issue](https://github.com/flamego/flamego/issues) or [start a discussion](https://github.com/flamego/flamego/discussions) on the [flamego/flamego](https://github.com/flamego/flamego) repository.
## License
This project is under the MIT License. See the [LICENSE](LICENSE) file for the full license text.