feat(Go-StudyExample): 2020/12/9 :新增Gin框架使用示例

This commit is contained in:
Huangzj
2020-12-09 09:45:46 +08:00
parent 9ad10e8cd9
commit 1361db0274
22 changed files with 881 additions and 0 deletions
+48
View File
@@ -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")
}