I want to add language prefix in url like localhost/en/someurl or localhost/de/someurl. I found this solution:
en := r.Group("/en")
{
en.GET("/someurl", ...)
...
}
de := r.Group("/de")
{
de.GET("/someurl", ...)
...
}
but it requires to repeat all routers and add new language will require another duplication. Can I avoid it with Gin?
How about using a path parameter instead?
r.Get("/:lang/someurl", ...)
In the handler you can then access the language:
func(c *gin.Context) {
lang := c.Param("lang")
// ...
}