@@ -2,32 +2,40 @@ package otp
22
33import (
44 "context"
5+ "fmt"
56
67 "github.com/android-sms-gateway/server/pkg/cache"
78)
89
9- // Storage wraps the cache interface for string values
10+ // Storage wraps the cache interface for string values.
1011type Storage struct {
1112 cache cache.Cache
1213}
1314
14- // NewStorage creates a new CodesCache with the underlying cache
15+ // NewStorage creates a new CodesCache with the underlying cache.
1516func NewStorage (c cache.Cache ) * Storage {
1617 return & Storage {cache : c }
1718}
1819
19- // SetOrFail is like Set, but returns an error if the key already exists
20+ // SetOrFail is like Set, but returns an error if the key already exists.
2021func (s * Storage ) SetOrFail (ctx context.Context , key string , value string , opts ... cache.Option ) error {
21- return s .cache .SetOrFail (ctx , key , []byte (value ), opts ... )
22+ if err := s .cache .SetOrFail (ctx , key , []byte (value ), opts ... ); err != nil {
23+ return fmt .Errorf ("failed to set cache item: %w" , err )
24+ }
25+
26+ return nil
2227}
2328
24- // GetAndDelete retrieves and deletes a string value
29+ // GetAndDelete retrieves and deletes a string value.
2530func (s * Storage ) GetAndDelete (ctx context.Context , key string ) (string , error ) {
2631 data , err := s .cache .GetAndDelete (ctx , key )
2732 return string (data ), err
2833}
2934
30- // Cleanup removes expired items
35+ // Cleanup removes expired items.
3136func (s * Storage ) Cleanup (ctx context.Context ) error {
32- return s .cache .Cleanup (ctx )
37+ if err := s .cache .Cleanup (ctx ); err != nil {
38+ return fmt .Errorf ("failed to cleanup cache: %w" , err )
39+ }
40+ return nil
3341}
0 commit comments