douji5329 2016-01-03 20:37
浏览 23

设置大猩猩多路复用器子路由器

If I have a mux.Router, how do I set it to be a "subrouter"? All examples I can find creates a new router by calling Route.Subrouter() and then setting Handlers on it, but I already have a router!

// does not know about "/api/v1/"
v1_router := mux.NewRouter()
subrouter.HandleFuc("/route1/", ...)
subrouter.HandleFuc("/route2/", ...)

// does not now about route1, route2
r := mux.NewRouter()
r.PathPrefix("/api/v1/").???(v1_router)

I hope I'm making sense...

  • 写回答

2条回答 默认 最新

  • dongyanghan0556 2016-02-16 17:04
    关注

    I feel the same way, and have to live with the same "workaround". I would like to set the subrouter to an existing router. Like:

    r.PathPrefix("/api").SetSubrouter(api.GetRouter()) //won't work
    

    That would let my api feel more autonomous / loosely coupled. But getting a subrouter is all we have from gorilla.

    s := r.PathPrefix("/api").Subrouter()
    api.SetRoutes(s)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程