func (a *Authenticator) Middleware() negroni.HandlerFunc { return func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { user := new(models.User) userID := a.session.Get(r, "UserID") if bson.IsObjectIdHex(userID) && user.FindByID(bson.ObjectIdHex(userID), a.database.Get(r)) == nil { a.currentUser.Set(r, user) } else { a.currentUser.Clear(r) } next(rw, r) } }