to options mode

This commit is contained in:
yanghao05
2023-04-27 18:30:39 +08:00
parent 8ae3d19aa9
commit 574736a878
20 changed files with 180 additions and 50 deletions

View File

@@ -7,8 +7,8 @@ import (
"github.com/mojocn/base64Captcha"
"github.com/rogeecn/atom/container"
"github.com/rogeecn/atom/providers"
"github.com/spf13/viper"
"go.uber.org/dig"
)
type CaptchaResponse struct {
@@ -22,7 +22,12 @@ type Captcha struct {
captcha *base64Captcha.Captcha
}
func Provide(conf *Config, opts ...dig.ProvideOption) error {
func Provide(o *providers.Options) error {
var conf Config
if err := o.UnmarshalConfig(&conf); err != nil {
log.Fatal(err)
}
return container.Container.Provide(func() (*Captcha, error) {
driver := base64Captcha.NewDriverDigit(
int(conf.Width),
@@ -36,7 +41,7 @@ func Provide(conf *Config, opts ...dig.ProvideOption) error {
return &Captcha{
captcha: base64Captcha.NewCaptcha(driver, store),
}, nil
})
}, o.DiOptions()...)
}
func (c *Captcha) OpenCaptchaTimeOutDuration() time.Duration {

View File

@@ -5,6 +5,8 @@ import (
"time"
)
const DefaultPrefix = "Captcha"
type Config struct {
Long uint // 验证码长度
Width uint // 验证码宽度