2024-07-05 16:12:30 +02:00
|
|
|
package hmac
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
2024-07-08 17:01:11 +02:00
|
|
|
// TokenStore is a simple in-memory store for token
|
2024-07-05 16:12:30 +02:00
|
|
|
// With this can update the token in thread safe way
|
2024-07-08 17:01:11 +02:00
|
|
|
type TokenStore struct {
|
2024-07-05 16:12:30 +02:00
|
|
|
mu sync.Mutex
|
|
|
|
token Token
|
|
|
|
}
|
|
|
|
|
2024-07-08 17:01:11 +02:00
|
|
|
func (a *TokenStore) UpdateToken(token Token) {
|
2024-07-05 16:12:30 +02:00
|
|
|
a.mu.Lock()
|
|
|
|
defer a.mu.Unlock()
|
|
|
|
a.token = token
|
|
|
|
}
|
|
|
|
|
2024-07-08 17:01:11 +02:00
|
|
|
func (a *TokenStore) Token() ([]byte, error) {
|
2024-07-05 16:12:30 +02:00
|
|
|
a.mu.Lock()
|
|
|
|
defer a.mu.Unlock()
|
|
|
|
return marshalToken(a.token)
|
|
|
|
}
|