Files
Go-StudyExample/example/gin/33-RouteGroup_test.go
T

49 lines
933 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* @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")
}