In my case need to catch request and check is internal request or not. If not, redirect these request to other handler function.
URL example:
1. URL: http://localhost/internal/dosomething1
2. URL: http://localhost/internal/dosomething2/:id
3. URL: http://localhost/overview
4. URL: http://localhost/xxx
Only the URIs that start with internal
should be handled in my own handle function (cases 1 and 2).
Others with any request method will proxy to another function (cases 3 and 4).
I am trying to use router.Any("/*uri", handlerExternal)
as such:
func handlerExternal(c *gin.Context) {
path := c.Param("uri")
if strings.HasPrefix(path, "/internal/") {
uri := strings.Split(path, "/")
switch uri[2] {
case "dosomething1":
doInternal(c)
}
} else {
doExternal(c)
}
}
But with this solution, the doInternal(c)
cannot catch path parameters like :id
as in http://localhost/internal/dosomething2/:id
Is there any better solution for this case?