gofiber-study/app/captcha.go
Shikong 72fb03ddbf 验证码简单实现
验证码添加 expire 超时时间
swag 添加 验证码测试
2022-10-25 11:40:24 +08:00

30 lines
702 B
Go

package app
import (
"github.com/go-redis/redis/v8"
"github.com/mojocn/base64Captcha"
"gofiber.study.skcks.cn/common/config"
"gofiber.study.skcks.cn/global"
)
var Store *global.CaptchaStore
func reloadCaptcha(c *config.BasicConfig, redis *redis.Client) {
driver := &base64Captcha.DriverString{
Height: c.Captcha.Height,
Width: c.Captcha.Width,
NoiseCount: c.Captcha.NoiseCount,
Fonts: []string{
"wqy-microhei.ttc",
},
ShowLineOptions: c.Captcha.ShowLineOptions,
Length: c.Captcha.Length,
Source: c.Captcha.Source,
BgColor: c.Captcha.BgColor,
}
Store = global.NewCaptchaStore(redis)
global.Captcha = base64Captcha.NewCaptcha(driver, Store)
}