V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
xnotepad

分享一个自己的路由工具

  •  
  •   xnotepad ·
    caixw · Nov 12, 2021 · 3388 views
    This topic created in 1629 days ago, the information mentioned may be changed or developed.
    项目在 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
    3 replies    2021-11-13 15:17:24 +08:00
    BeijingBaby
        1
    BeijingBaby  
       Nov 12, 2021
    这类轮子太多了
    xnotepad
        2
    xnotepad  
    OP
       Nov 12, 2021
    @BeijingBaby 没办法,水平有限,只能造一些简单的轮子。
    liaohongxing
        3
    liaohongxing  
       Nov 13, 2021   ❤️ 1
    楼主的 identicon 一直在用。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2981 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 112ms · UTC 15:02 · PVG 23:02 · LAX 08:02 · JFK 11:02
    ♥ Do have faith in what you're doing.