package cache import "sync" var tokenMap sync.Map type tokenInfo struct { Token string TimeOut int } func SaveToken(key string, timeOut int, token string) { tokenMap.Store(key, &tokenInfo{ Token: token, TimeOut: timeOut, }) } func GetToken(key string) *tokenInfo { txv, ok := tokenMap.Load(key) if ok { return txv.(interface{}).(*tokenInfo) } else { return nil } return nil }