Gin middleware/handler to enable HCaptcha support.
Download and install it:
go get github.com/kleash/gin-hcaptcha
Import it in your code:
import "github.com/kleash/gin-hcaptcha"
package main
import (
. "github.com/kleash/gin-hcaptcha"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
hCaptchaMw, err := NewWithDefaults("0x0000000000000000000000000000000000000000")
if err != nil {
panic(err.Error())
}
router.POST("/", hCaptchaMw.MiddlewareFunc(), func(c *gin.Context) {
c.String(200, "good")
})
}
Config | Description | Default Value |
---|---|---|
SiteKey | Set this to validate site key | |
EnableUserIpValidation | Validate User Ip Also | false |
ErrResp | Custom error response function | {"message": "invalid captcha} HTTP Status Code = 403 |
HttpClient | Custom http client to communicate with HCaptcha Server | http.Client{Timeout: 10s} |
GetCaptchaResponse | Custom function to get captcha response | Value of h-captcha-response from form value |
HCaptchaUrl | HCaptcha server url | https://hcaptcha.com/siteverify |