douli1872 2014-07-17 12:53
浏览 21
已采纳

大猩猩复用器子路由器空路径

i want to create a /user subrouter as following

user := app.Router.PathPrefix("/user").Subrouter()
user.HandleFunc("/create", (&controllers.User{c}).Create)
user.HandleFunc("", (&controllers.User{c}).Create).Methods("POST")
user.HandleFunc("", (&controllers.User{c}).FindAll).Methods("GET")
user.HandleFunc("/{id}", (&controllers.User{c}).Update).Methods("PUT")
user.HandleFunc("/{id}", (&controllers.User{c}).Destroy).Methods("DELETE")
user.HandleFunc("/{id}", (&controllers.User{c}).FindOne).Methods("GET")

the problem is the domain/user doenst work. i can do this

user.HandleFunc("/", (&controllers.User{c}).Create).Methods("POST")

but then it only matches domain/user/ any idea how to fix this

  • 写回答

2条回答 默认 最新

  • douhao2856 2014-07-17 16:42
    关注

    If setting strict slash to true won't work for you, then you may have to handle the routes without a slash in the router rather than using a subrouter:

    app.Router.HandleFunc("/user", (&controllers.User{c}).Create).Methods("POST")
    app.Router.HandleFunc("/user", (&controllers.User{c}).FindAll).Methods("GET")
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 eclipse连接sap后代码跑出来空白
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi