dou12352 2016-06-30 14:59
浏览 80

Golang中间件身份验证取决于路由

I am building an API in Go. I handle all authentication by including a secret token in the header. I have added some middleware using negroni that picks this out of the header and checks the database to see if it exists.

This is fine but now I want to do permissions based upon the route in question. I have a table in a database with permissions for only some routes etc and I would like to use this logic in the middleware so that the handlers never need to worry about it.

My problem is that the middleware needs to know what handler is being called so that it can check for the correct record in the database. What is the best way to pass or extract the current route / handler using negroni?

Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题