这节课讲解一个知识点,分组路由git
有时候为了代码可读性更好,维护更好,咱们就须要路由分组了github
官方教程直达浏览器
https://github.com/gin-gonic/ginpost
func main() { r:=gin.Default() //r.GET("v1/topics", func(c *gin.Context) { // if c.Query("username")=="" { // c.String(http.StatusOK, "获取所有帖子") // }else { // c.String(http.StatusOK, "获取用户%s的帖子", c.Query("username")) // } //}) // //r.GET("v1/topics/:topic_id", func(c *gin.Context) { // c.String(http.StatusOK, "获取帖子I为%s的信息",c.Param("topic_id")) //}) // //r.Run(":9090") topic:=r.Group("v1/topics") { //这个只是块,跟topic没有任何关系 topic.GET("", func(c *gin.Context) { if c.Query("username")=="" { c.String(http.StatusOK, "获取所有帖子--group") }else { c.String(http.StatusOK, "获取用户%s的帖子--group", c.Query("username")) } }) topic.GET("/:topic_id", func(c *gin.Context) { c.String(http.StatusOK, "获取帖子I为%s的信息",c.Param("topic_id")) }) } //在代码块外面同样能够使用,进一步说明代码块跟分组路由没有任何关系 topic.POST("", func(c *gin.Context) { c.String(http.StatusOK, "post post") }) r.Run(":9090") }
浏览器愉快查看吧spa
*************************************************************************************code
post方式呢blog
*************************************************************************************教程
好了,这节课先到这里路由