douliang9057 2019-05-03 16:12
浏览 164
已采纳

我如何在杜松子酒的URL中有一个带有斜杠的参数

I want to have a parameter with slashes in the router in gin.

From what I gathered I can do this by adding a wildcard to the URL. For example: /api/v0/files/*addr

But this approach doesn't work if I want to have the addr in the middle of the URL and it returns this error catch-all routes are only allowed at the end of the path. Like: /api/v0/*addr/files

I was wondering whether there is another way of having it?

  • 写回答

1条回答 默认 最新

  • dongqie4233 2019-05-03 16:20
    关注

    Seems that is a limitation of the Gin framework, as seen @ https://github.com/gin-gonic/gin/blob/master/tree.go#L322

    You could always invert the order and do a rewrite using a proxy and a regexp (i.e. /api/v0/*addr/files to /api/v0/files/*addr) or only accept methods ending with /files inside your handling function, but I'm afraid that is a hardcoded limitation of the Gin framework.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面