| 1 |
package tokenstorage |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"time" |
| 6 |
) |
| 7 |
|
| 8 |
// Storage defines the interface for token storage implementations. |
| 9 |
// All methods accept a context for cancellation and timeout support. |
| 10 |
type Storage interface { |
| 11 |
// Get retrieves a token for the given client identifier. |
| 12 |
// Returns ErrNotExists if the token does not exist or has expired. |
| 13 |
Get(ctx context.Context, client string) (string, error) |
| 14 |
|
| 15 |
// Consume atomically retrieves and removes a token for the given client identifier. |
| 16 |
// Returns ErrNotExists if the token does not exist or has expired. |
| 17 |
Consume(ctx context.Context, client string) (string, error) |
| 18 |
|
| 19 |
// Set stores a token for the given client identifier. |
| 20 |
Set(ctx context.Context, client string, token string) error |
| 21 |
|
| 22 |
// Delete removes a token for the given client identifier. |
| 23 |
Delete(ctx context.Context, client string) error |
| 24 |
|
| 25 |
// Close releases any resources held by the storage. |
| 26 |
Close() error |
| 27 |
} |
| 28 |
|
| 29 |
type item struct { |
| 30 |
Expires time.Time |
| 31 |
Data []byte |
| 32 |
} |
| 33 |
|
| 34 |
type DataMap map[string]item |