token.go 401 B

1234567891011121314151617181920212223242526
  1. package cache
  2. import "sync"
  3. var tokenMap sync.Map
  4. type tokenInfo struct {
  5. Token string
  6. TimeOut int
  7. }
  8. func SaveToken(key string, timeOut int, token string) {
  9. tokenMap.Store(key, &tokenInfo{
  10. Token: token,
  11. TimeOut: timeOut,
  12. })
  13. }
  14. func GetToken(key string) *tokenInfo {
  15. txv, ok := tokenMap.Load(key)
  16. if ok {
  17. return txv.(interface{}).(*tokenInfo)
  18. } else {
  19. return nil
  20. }
  21. return nil
  22. }