세션 해제 콜백 추가
This commit is contained in:
@ -182,12 +182,20 @@ func newConsumerWithMongo(ctx context.Context, mongoUrl string, ttl time.Duratio
|
||||
consumer.add(data.Session.Key, data.DocumentKey.Id, data.Session)
|
||||
case "update":
|
||||
if data.Session == nil {
|
||||
consumer.deleteById(data.DocumentKey.Id)
|
||||
if old := consumer.deleteById(data.DocumentKey.Id); old != nil {
|
||||
for _, f := range consumer.onSessionInvalidated {
|
||||
f(old.Auth.Account)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
consumer.add(data.Session.Key, data.DocumentKey.Id, data.Session)
|
||||
}
|
||||
case "delete":
|
||||
consumer.deleteById(data.DocumentKey.Id)
|
||||
if old := consumer.deleteById(data.DocumentKey.Id); old != nil {
|
||||
for _, f := range consumer.onSessionInvalidated {
|
||||
f(old.Auth.Account)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.Error("watchAuthCollection stream.Decode failed :", err)
|
||||
@ -338,12 +346,17 @@ func (c *consumer_mongo) add(sk storagekey, id primitive.ObjectID, si *sessionMo
|
||||
c.ids[id] = sk
|
||||
}
|
||||
|
||||
func (c *consumer_mongo) deleteById(id primitive.ObjectID) {
|
||||
func (c *consumer_mongo) deleteById(id primitive.ObjectID) (old *sessionMongo) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
if sk, ok := c.ids[id]; ok {
|
||||
c.consumer_common.delete_internal(sk)
|
||||
old = c.consumer_common.delete_internal(sk)
|
||||
delete(c.ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *consumer_mongo) RegisterOnSessionInvalidated(cb func(primitive.ObjectID)) {
|
||||
c.onSessionInvalidated = append(c.onSessionInvalidated, cb)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user