简体   繁体   中英

How can I have a parameter with slashes in gin 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 like /api/v0/*addr/files , and it returns this error:

catch-all routes are only allowed at the end of the path.

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

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 (ie /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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM