Image now passed by a pointer instead of value. Hope it will help with memory consumption a little.
This commit is contained in:
parent
18431e0001
commit
59bd479ebe
@ -24,7 +24,7 @@ func NewDwellingCaptcha(expiry time.Duration) *DwellingCaptcha {
|
||||
ExpireIn: captcha.ExpiryDate(expiry)}}
|
||||
}
|
||||
|
||||
func (c *DwellingCaptcha) Image(style string) image.Image {
|
||||
func (c *DwellingCaptcha) Image(style string) *image.Image {
|
||||
isDark := style == "dark"
|
||||
ctx := gg.NewContext(dwImageWidth, dwImageHeight)
|
||||
|
||||
@ -67,5 +67,6 @@ func (c *DwellingCaptcha) Image(style string) image.Image {
|
||||
ctx.Stroke()
|
||||
}
|
||||
|
||||
return ctx.Image()
|
||||
i := ctx.Image()
|
||||
return &i
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ func New(data string, captcha captcha.Captcha) (captcha.Captcha, captcha.ID) {
|
||||
return captchaDb.New(data, captcha)
|
||||
}
|
||||
|
||||
func Image(id captcha.ID, style string) (image.Image, error) {
|
||||
func Image(id captcha.ID, style string) (*image.Image, error) {
|
||||
return captchaDb.Image(id, style)
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ func (h *CaptchaHandlers) Image(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Header().Add("Content-Disposition", "inline; filename=\""+string(captchaID)+"\"")
|
||||
|
||||
png.Encode(w, captchaImage)
|
||||
png.Encode(w, *captchaImage)
|
||||
}
|
||||
|
||||
func (h *CaptchaHandlers) Solve(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -21,7 +21,7 @@ func NewIntAnswer() Answer {
|
||||
// Captcha interface that should be implemented by captcha.
|
||||
type Captcha interface {
|
||||
// Image generates and returns an image of captcha.
|
||||
Image(style string) image.Image
|
||||
Image(style string) *image.Image
|
||||
// GetAnswer returns a pregenerated answer.
|
||||
GetAnswer() Answer
|
||||
// Solve compares a stored answer with a passed one.
|
||||
|
@ -87,7 +87,7 @@ func (cdb *InMemoryCaptchaDB) GetExpiry() time.Duration {
|
||||
}
|
||||
|
||||
// Image returns image for a captcha.
|
||||
func (cdb *InMemoryCaptchaDB) Image(id ID, style string) (image.Image, error) {
|
||||
func (cdb *InMemoryCaptchaDB) Image(id ID, style string) (*image.Image, error) {
|
||||
cdb.Lock()
|
||||
defer cdb.Unlock()
|
||||
if c, ok := cdb.DB[id]; ok {
|
||||
|
Loading…
Reference in New Issue
Block a user