mirror of
https://github.com/kataras/iris.git
synced 2026-01-23 03:45:56 +00:00
replace ioutil with io package and other minor improvements
This commit is contained in:
@@ -3,7 +3,7 @@ package recaptcha
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
@@ -50,7 +50,9 @@ func New(secret string) context.Handler {
|
||||
}
|
||||
|
||||
// SiteVerify accepts context and the secret key(https://www.google.com/recaptcha)
|
||||
// and returns the google's recaptcha response, if `response.Success` is true
|
||||
//
|
||||
// and returns the google's recaptcha response, if `response.Success` is true
|
||||
//
|
||||
// then validation passed.
|
||||
//
|
||||
// Use `New` for middleware use instead.
|
||||
@@ -74,7 +76,7 @@ func SiteVerify(ctx *context.Context, secret string) (response Response) {
|
||||
return
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
r.Body.Close()
|
||||
if err != nil {
|
||||
response.ErrorCodes = append(response.ErrorCodes, err.Error())
|
||||
@@ -113,22 +115,24 @@ var recaptchaForm = `<form action="%s" method="POST">
|
||||
// Example Code:
|
||||
//
|
||||
// Method: "POST" | Path: "/contact"
|
||||
// func postContact(ctx *context.Context) {
|
||||
// // [...]
|
||||
// response := recaptcha.SiteVerify(ctx, recaptchaSecret)
|
||||
//
|
||||
// if response.Success {
|
||||
// // [your action here, i.e sendEmail(...)]
|
||||
// }
|
||||
// func postContact(ctx *context.Context) {
|
||||
// // [...]
|
||||
// response := recaptcha.SiteVerify(ctx, recaptchaSecret)
|
||||
//
|
||||
// ctx.JSON(response)
|
||||
// }
|
||||
// if response.Success {
|
||||
// // [your action here, i.e sendEmail(...)]
|
||||
// }
|
||||
//
|
||||
// ctx.JSON(response)
|
||||
// }
|
||||
//
|
||||
// Method: "GET" | Path: "/contact"
|
||||
// func getContact(ctx *context.Context) {
|
||||
// // render the recaptcha form
|
||||
// ctx.HTML(recaptcha.GetFormHTML(recaptchaPublic, "/contact"))
|
||||
// }
|
||||
//
|
||||
// func getContact(ctx *context.Context) {
|
||||
// // render the recaptcha form
|
||||
// ctx.HTML(recaptcha.GetFormHTML(recaptchaPublic, "/contact"))
|
||||
// }
|
||||
func GetFormHTML(dataSiteKey string, postActionRelativePath string) string {
|
||||
return fmt.Sprintf(recaptchaForm, postActionRelativePath, dataSiteKey)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user