Home >Backend Development >Golang >How to Resolve Gin Wildcard Route Conflicts with Existing Children?
Gin Wildcard Route Conflicts with Existing Children
You want to create a Gin program with the following routes:
r.GET("/special", ... // Serves a special resource. r.Any("/*", ... // Serves a default resource.
However, this program panics at runtime due to a conflict between the wildcard route and the existing children.
Solution
Use the gin.NoRoute(...) function to serve the default resource for all endpoints except the one with a special resource:
r.GET("/special", func(c *gin.Context) { // Serve the special resource... r.NoRoute(func(c *gin.Context) { // Serve the default resource...
This method allows you to handle both special and default resources within the same Gin program.
The above is the detailed content of How to Resolve Gin Wildcard Route Conflicts with Existing Children?. For more information, please follow other related articles on the PHP Chinese website!