问题内容
在 crystal#kemal 中,我有 before_all 方法,它将作为请求的网关(以及用于身份验证检查)
before_all do |env|
# go to /login if user doesn't have cookie (set cookie on login)
if env.request.path != "/login"
if env.request.cookies.has_key?("guid") == false
env.redirect "/login"
else
user_guid = env.request.cookies["guid"].value
# if in redis is logged, but not in the app
if is_logged_in(user_guid)
if !is_logged(env)
app_sess_set(env, user_guid)
end
else
env.redirect "/login"
end
end
end
end
revel 是否有像 before_all 这样的方法,我可以像 kemal 那样做吗?
解决方案
func (c App) SessionProcess() revel.Result {
# do action
return nil
}
func init() {
revel.InterceptMethod(App.SessionProcess, revel.BEFORE)
}
到这里,我们也就讲完了《使用 Redis 进行 Revel 会话集群》的内容了。个人认为,基础知识的学习和巩固,是为了更好的将其运用到项目中,欢迎关注公众号,带你了解更多关于的知识点!