package token import ( "errors" "fmt" "mtp2_if/rediscli" ) var TokenMap map[int]string func Init() { TokenMap = make(map[int]string) TokenMap[250000000001] = "testtoken" } func CheckToken(accountid int, token string) (bool, error) { realToken, ok := TokenMap[accountid] if ok { if realToken != token { return false, errors.New("token is invalid") } } else { key := fmt.Sprintf("monitor:online_loginid::%d", accountid) field := "Token" realToken, err := rediscli.GetRedisClient().HGet(key, field).Result() if err != nil { return false, err } TokenMap[accountid] = realToken if realToken != token { return false, errors.New("token is invalid") } } return true, nil }