-
Notifications
You must be signed in to change notification settings - Fork 60
route
hetiansu5 edited this page Jul 8, 2019
·
2 revisions
构建最基本的路由只需要一个URI与一个闭包或者回调函数。
app/http/routes/route.go
router.GET({路径}, {对应的执行函数})
router.GET("/someGet", getting)
router.POST("/somePost", posting)
router.PUT("/somePut", putting)
router.DELETE("/someDelete", deleting)
router.PATCH("/somePatch", patching)
router.HEAD("/someHead", head)
router.OPTIONS("/someOptions", options)
api 参数通过Context的Param方法来获取
router.GET("/string/:name", func(c *gin.Context) {
name := c.Param("name")
fmt.Println("Hello %s", name)
})
someGroup := router.Group("/someGroup")
{
someGroup.GET("/someGet", getting)
someGroup.POST("/somePost", posting)
}