Add AmIAllowed func to tokens package

This commit is contained in:
qowevisa 2024-08-03 08:22:01 +03:00
parent 20c3beef53
commit bfa9af930e

View File

@ -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
}