1 Star 1 Fork 0

teamlint / iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 919 Bytes
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/middleware/recaptcha"
)
// keys should be obtained by https://www.google.com/recaptcha
const (
recaptchaPublic = ""
recaptchaSecret = ""
)
func showRecaptchaForm(ctx iris.Context, path string) {
ctx.HTML(recaptcha.GetFormHTML(recaptchaPublic, path))
}
func main() {
app := iris.New()
// On both Get and Post on this example, so you can easly
// use a single route to show a form and the main subject if recaptcha's validation result succeed.
app.HandleMany("GET POST", "/", func(ctx iris.Context) {
if ctx.Method() == iris.MethodGet {
showRecaptchaForm(ctx, "/")
return
}
result := recaptcha.SiteFerify(ctx, recaptchaSecret)
if !result.Success {
/* redirect here if u want or do nothing */
ctx.HTML("<b> failed please try again </b>")
return
}
ctx.Writef("succeed.")
})
app.Run(iris.Addr(":8080"))
}
Go
1
https://gitee.com/teamlint/iris.git
git@gitee.com:teamlint/iris.git
teamlint
iris
iris
v11.1.1

搜索帮助