2

分享一个自己的路由工具

 2 years ago
source link: https://www.v2ex.com/t/814811
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  Go 编程语言

分享一个自己的路由工具

  xnotepad · 2 小时 21 分钟前 · 156 次点击
项目在 https://github.com/issue9/mux

能够自动生成 OPTIONS 和 HEAD 的请求处理方式;
也支持类似于 discuz 的路由风格,不会假定两个参数之间必须要有一个 / 符号分隔;
能正确区分不同类型的参数,比如 `/posts/{id}` 和 `/posts/{id:\\d+}`,只有无法匹配后者的时候,才会尝试匹配前者;
其它的中间件什么的也都有,感觉也玩不出什么花来了。

维护了大概有 4-5 年时间,目前刚更新到 v5 版本,删除了部分无用的功能,个人感觉已经比较稳定了,该有的功能也都有了,性能上也不算太差,兼容官方的 http.Handler 接口。有兴趣的可以试试。

关于性能,我自己做了一个对比数据: https://caixw.github.io/go-http-routers-testing/

同时也提供了一组常用的中间件: https://github.com/issue9/middleware

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK