https://github.com/flamego/hcaptcha
Package hcaptcha is a middleware that provides hCaptcha integration for Flamego
https://github.com/flamego/hcaptcha
captcha flamego go hcaptcha middleware
Last synced: 5 months ago
JSON representation
Package hcaptcha is a middleware that provides hCaptcha integration for Flamego
- Host: GitHub
- URL: https://github.com/flamego/hcaptcha
- Owner: flamego
- License: mit
- Created: 2022-03-07T12:45:24.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-01-01T16:18:16.000Z (over 1 year ago)
- Last Synced: 2025-01-01T17:20:48.204Z (over 1 year ago)
- Topics: captcha, flamego, go, hcaptcha, middleware
- Language: Go
- Homepage:
- Size: 44.9 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hcaptcha
[](https://github.com/flamego/hcaptcha/actions?query=branch%3Amain)
[](https://pkg.go.dev/github.com/flamego/hcaptcha?tab=doc)
Package hcaptcha is a middleware that provides hCaptcha rendering integration for [Flamego](https://github.com/flamego/flamego).
## Installation
```zsh
go get github.com/flamego/hcaptcha
```
## Getting started
```html
```
```go
package main
import (
"fmt"
"net/http"
"github.com/flamego/flamego"
"github.com/flamego/hcaptcha"
"github.com/flamego/template"
)
func main() {
f := flamego.Classic()
f.Use(template.Templater())
f.Use(hcaptcha.Captcha(
hcaptcha.Options{
Secret: "",
},
))
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, h hcaptcha.HCaptcha) {
token := r.PostFormValue("h-captcha-response")
resp, err := h.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/hcaptcha.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.