Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I have a parameter with slashes in gin url

Tags:

go

go-gin

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?

like image 378
taraf Avatar asked Nov 01 '25 05:11

taraf


1 Answers

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.

like image 74
Gustavo Kawamoto Avatar answered Nov 03 '25 20:11

Gustavo Kawamoto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!