From ca5b399975a1011278ffd15a9be30001cc20e588 Mon Sep 17 00:00:00 2001 From: MuZhou233 Date: Wed, 13 Mar 2024 12:49:54 +0000 Subject: [PATCH] fix: fix captcha delete --- internal/lib/libcache/captcha.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/lib/libcache/captcha.go b/internal/lib/libcache/captcha.go index 96343a0..2947198 100644 --- a/internal/lib/libcache/captcha.go +++ b/internal/lib/libcache/captcha.go @@ -17,11 +17,11 @@ type captchaStoreImpl struct { } func (c *captchaStoreImpl) Set(id string, digits []byte) { - _ = c.store.Set(context.Background(), captchaStoreKey+":"+id, string(digits), WithExpiration(captcha.Expiration)) + _ = c.store.Set(context.Background(), c.key(id), string(digits), WithExpiration(captcha.Expiration)) } func (c *captchaStoreImpl) Get(id string, clear bool) []byte { - get, err := c.store.Get(context.Background(), captchaStoreKey+":"+id) + get, err := c.store.Get(context.Background(), c.key(id)) if err != nil { return nil } @@ -30,7 +30,11 @@ func (c *captchaStoreImpl) Get(id string, clear bool) []byte { return nil } if clear { - _ = c.store.Delete(context.Background(), captchaStoreKey+id) + _ = c.store.Delete(context.Background(), c.key(id)) } return []byte(digits) } + +func (c *captchaStoreImpl) key(id string) string { + return captchaStoreKey + ":" + id +}