Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion captcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ func (c *Captcha) Generate() (id, b64s string, err error) {
if err != nil {
return "", "", err
}
c.Store.Set(id, answer)
err = c.Store.Set(id, answer)
if err != nil {
return "", "", err
}
b64s = item.EncodeB64string()
return
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/mojocn/base64Captcha
module github.com/golifes/base64Captcha

go 1.12

Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF0
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
golang.org/x/image v0.0.0-20190501045829-6d32002ffd75 h1:TbGuee8sSq15Iguxu4deQ7+Bqq/d2rsQejGcEtADAMQ=
golang.org/x/image v0.0.0-20190501045829-6d32002ffd75/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
2 changes: 1 addition & 1 deletion interface_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package base64Captcha
// method after the certain amount of captchas has been stored.)
type Store interface {
// Set sets the digits for the captcha id.
Set(id string, value string)
Set(id string, value string) error

// Get returns stored digits for the captcha id. Clear indicates
// whether the captcha must be deleted from the store.
Expand Down
3 changes: 2 additions & 1 deletion store_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewMemoryStore(collectNum int, expiration time.Duration) Store {
return s
}

func (s *memoryStore) Set(id string, value string) {
func (s *memoryStore) Set(id string, value string) error {
s.Lock()
s.digitsById[id] = value
s.idByTime.PushBack(idByTimeValue{time.Now(), id})
Expand All @@ -62,6 +62,7 @@ func (s *memoryStore) Set(id string, value string) {
if s.numStored > s.collectNum {
go s.collect()
}
return nil
}

func (s *memoryStore) Verify(id, answer string, clear bool) bool {
Expand Down
4 changes: 2 additions & 2 deletions store_memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ func TestSetGet(t *testing.T) {
s := NewMemoryStore(GCLimitNumber, Expiration)
id := "captcha id"
d := "random-string"
s.Set(id, d)
err := s.Set(id, d)
d2 := s.Get(id, false)
if d2 != d {
t.Errorf("saved %v, getDigits returned got %v", d, d2)
t.Errorf("saved %v, getDigits returned got %v", d, d2, err)
}
}

Expand Down