mae*_*ics 5 web-services go go-gin
我想建立一个gin服务于以下路线的程序:
r.GET("/special", ... // Serves a special resource.
r.Any("/*", ... // Serves a default resource.
Run Code Online (Sandbox Code Playgroud)
然而,这样的程序在运行时会出现恐慌:
r.GET("/special", ... // Serves a special resource.
r.Any("/*", ... // Serves a default resource.
Run Code Online (Sandbox Code Playgroud)
是否可以创建一个 gin 程序,为每个路由提供默认资源,除了服务于不同资源的单个路由之外?
网络上的许多页面让我相信使用默认的 gin 路由器是不可能的,那么从 gin 程序提供这些路由的最简单方法是什么?
看起来这个gin.NoRoute(...)函数可以解决问题。
r.GET("/special", func(c *gin.Context) { // Serve the special resource...
r.NoRoute(func(c *gin.Context) { // Serve the default resource...
Run Code Online (Sandbox Code Playgroud)