feat(Go-StudyExample): 2020/12/9 :新增Gin框架使用示例
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* @Author : huangzj
|
||||
* @Time : 2020/12/8 16:15
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
package gin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"testing"
|
||||
)
|
||||
|
||||
//路有组就是把相同前缀的路由路径分在一起。
|
||||
func TestRouteGroup(t *testing.T) {
|
||||
router := gin.Default()
|
||||
|
||||
// 简单的路由组: v1
|
||||
v1 := router.Group("/v1")
|
||||
{
|
||||
v1.POST("/login", func(context *gin.Context) {
|
||||
fmt.Println(context.Params)
|
||||
})
|
||||
v1.POST("/submit", func(context *gin.Context) {
|
||||
fmt.Println(context.Params)
|
||||
})
|
||||
v1.POST("/read", func(context *gin.Context) {
|
||||
fmt.Println(context.Params)
|
||||
})
|
||||
}
|
||||
|
||||
// 简单的路由组: v2
|
||||
v2 := router.Group("/v2")
|
||||
{
|
||||
v2.POST("/login", func(context *gin.Context) {
|
||||
fmt.Println(context.Params)
|
||||
})
|
||||
v2.POST("/submit", func(context *gin.Context) {
|
||||
fmt.Println(context.Params)
|
||||
})
|
||||
v2.POST("/read", func(context *gin.Context) {
|
||||
fmt.Println(context.Params)
|
||||
})
|
||||
}
|
||||
|
||||
_ = router.Run(":8080")
|
||||
}
|
||||
Reference in New Issue
Block a user