mirror of
https://github.com/astaxie/beego.git
synced 2024-11-24 19:10:53 +00:00
Decouple web module from cache module
This commit is contained in:
parent
9a7c43c404
commit
03498529b9
@ -68,7 +68,6 @@ import (
|
||||
|
||||
"github.com/astaxie/beego/pkg/infrastructure/logs"
|
||||
|
||||
"github.com/astaxie/beego/pkg/client/cache"
|
||||
"github.com/astaxie/beego/pkg/infrastructure/utils"
|
||||
"github.com/astaxie/beego/pkg/server/web"
|
||||
"github.com/astaxie/beego/pkg/server/web/context"
|
||||
@ -91,7 +90,7 @@ const (
|
||||
// Captcha struct
|
||||
type Captcha struct {
|
||||
// beego cache store
|
||||
store cache.Cache
|
||||
store Storage
|
||||
|
||||
// url prefix for captcha image
|
||||
URLPrefix string
|
||||
@ -232,7 +231,7 @@ func (c *Captcha) Verify(id string, challenge string) (success bool) {
|
||||
}
|
||||
|
||||
// NewCaptcha create a new captcha.Captcha
|
||||
func NewCaptcha(urlPrefix string, store cache.Cache) *Captcha {
|
||||
func NewCaptcha(urlPrefix string, store Storage) *Captcha {
|
||||
cpt := &Captcha{}
|
||||
cpt.store = store
|
||||
cpt.FieldIDName = fieldIDName
|
||||
@ -258,7 +257,7 @@ func NewCaptcha(urlPrefix string, store cache.Cache) *Captcha {
|
||||
|
||||
// NewWithFilter create a new captcha.Captcha and auto AddFilter for serve captacha image
|
||||
// and add a template func for output html
|
||||
func NewWithFilter(urlPrefix string, store cache.Cache) *Captcha {
|
||||
func NewWithFilter(urlPrefix string, store Storage) *Captcha {
|
||||
cpt := NewCaptcha(urlPrefix, store)
|
||||
|
||||
// create filter for serve captcha image
|
||||
@ -269,3 +268,12 @@ func NewWithFilter(urlPrefix string, store cache.Cache) *Captcha {
|
||||
|
||||
return cpt
|
||||
}
|
||||
|
||||
type Storage interface {
|
||||
// Get a cached value by key.
|
||||
Get(key string) interface{}
|
||||
// Set a cached value with key and expire time.
|
||||
Put(key string, val interface{}, timeout time.Duration) error
|
||||
// Delete cached value by key.
|
||||
Delete(key string) error
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user