package logic import ( "strconv" ) // PairKeyMode controls refresh token storage key shape. type PairKeyMode string const ( PairKeyTriple PairKeyMode = "triple" // (user_id, device_id, app_id) PairKeyPair PairKeyMode = "pair" // (user_id, device_id) ) func (m PairKeyMode) Valid() bool { return m == PairKeyTriple || m == PairKeyPair } func normalizePairKeyMode(m PairKeyMode) PairKeyMode { if m.Valid() { return m } return PairKeyTriple } func storageKey(mode PairKeyMode, userID int64, deviceID uint64, appID uint32) string { if normalizePairKeyMode(mode) == PairKeyPair { return strconv.FormatInt(userID, 10) + ":" + strconv.FormatUint(deviceID, 10) } return strconv.FormatInt(userID, 10) + ":" + strconv.FormatUint(deviceID, 10) + ":" + strconv.FormatUint(uint64(appID), 10) } func userKeyPrefix(userID int64) string { return strconv.FormatInt(userID, 10) + ":" } func deviceKeyPrefix(userID int64, deviceID uint64) string { return strconv.FormatInt(userID, 10) + ":" + strconv.FormatUint(deviceID, 10) }