diff --git a/tokens/dispatcher.go b/tokens/dispatcher.go index 911b09a..17459ec 100644 --- a/tokens/dispatcher.go +++ b/tokens/dispatcher.go @@ -67,12 +67,13 @@ var ( ) func GetToken(id uint) (*Token, error) { - toks.Mu.RLock() + toks.Mu.Lock() + defer toks.Mu.Unlock() val, exists := toks.Tokmap[id] - toks.Mu.RUnlock() if !exists { return nil, ERROR_DONT_HAVE_TOKEN } + val.LastActive = time.Now() return val, nil } @@ -138,3 +139,14 @@ func AddToken(id uint) (*Token, error) { toks.Mu.Unlock() return token, nil } + +func AmIAllowed(token string) bool { + toks.Mu.Lock() + defer toks.Mu.Unlock() + val, exists := toks.TokmapRev[token] + if !exists { + return false + } + val.LastActive = time.Now() + return true +}