httprouter icon indicating copy to clipboard operation
httprouter copied to clipboard

How to support part of the pathinfo

Open ghost opened this issue 5 years ago • 1 comments

For example, we want to rewrite /forum-{:id}.html to match the id from the part of the url.

i don't know how to do it.

:id was the named params.

if id = 4

request may like /forum-4.html

For reference: Spring framework has PathPattern very powerful

  • PathPattern Implementation https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java

  • Test cases https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternTests.java

ghost avatar Nov 16 '20 01:11 ghost

you can use /forum-:id, but not through ps.ByName("id") get id, you can self parse id, like

id, err := strconv.Atoi("/forml-4"[len("/forml-"):])

Fov6363 avatar Jan 17 '22 12:01 Fov6363