astaxie / build-web-application-with-golang

A golang ebook intro how to build a web with golang
BSD 3-Clause "New" or "Revised" License
43.31k stars 10.64k forks source link

6.3 session存储 SessionGC() 问题 #1026

Open dchaofei opened 6 years ago

dchaofei commented 6 years ago

方法里最后一个 break 是不是改为 continue?

func (pder *Provider) SessionGC(maxlifetime int64) {
    pder.lock.Lock()
    defer pder.lock.Unlock()

    for {
        element := pder.list.Back()
        if element == nil {
            break
        }
        if (element.Value.(*SessionStore).timeAccessed.Unix() + maxlifetime) < time.Now().Unix() {
            pder.list.Remove(element)
            delete(pder.sessions, element.Value.(*SessionStore).sid)
        } else {
            break
        }
    }
}
AInoriex commented 2 years ago

同感,应该是用continue,为空才break,还有就continue