From 2d61d59179caa9011d685e423238526fc40ba81b Mon Sep 17 00:00:00 2001 From: qowevisa Date: Sat, 3 Aug 2024 08:48:33 +0300 Subject: [PATCH] Add Id to tokens.Token struct and func GetID to tokens package --- tokens/dispatcher.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tokens/dispatcher.go b/tokens/dispatcher.go index 17459ec..6735951 100644 --- a/tokens/dispatcher.go +++ b/tokens/dispatcher.go @@ -11,6 +11,7 @@ import ( ) type Token struct { + Id uint Val string LastActive time.Time } @@ -77,6 +78,16 @@ func GetToken(id uint) (*Token, error) { return val, nil } +func GetID(token string) (uint, error) { + toks.Mu.RLock() + val, exists := toks.TokmapRev[token] + toks.Mu.RUnlock() + if !exists { + return 0, ERROR_DONT_HAVE_TOKEN + } + return val.Id, nil +} + func haveToken(id uint) bool { toks.Mu.RLock() _, exists := toks.Tokmap[id] @@ -130,6 +141,7 @@ func AddToken(id uint) (*Token, error) { } val := generateTokenVal() token := &Token{ + Id: id, Val: val, LastActive: time.Now(), }