gin框架使用【5.路由分组】

package main

import (
"github.com/gin-gonic/gin"
)

func main() {
router := gin.Default()
v1RouterGroup := router.Group("/v1")
{
v1RouterGroup.GET("/users", func(c *gin.Context) {
c.JSON(200, gin.H{
"path" : "/users",
"method" : "GET",
})
})
v1RouterGroup.POST("/users", func(c *gin.Context) {
c.JSON(200, gin.H{
"path" : "/users",
"method" : "POST",
})
})
}

v2RouterGroup := router.Group("/v2")
{
v2RouterGroup.GET("/users", func(c *gin.Context) {
c.JSON(200, gin.H{
"path" : "/users",
"method" : "GET",
})
})
v2RouterGroup.POST("/users", func(c *gin.Context) {
c.JSON(200, gin.H{
"path" : "/users",
"method" : "POST",
})
})
}
router.Run(":8080")
}

  

原文地址:https://www.cnblogs.com/juanmaofeifei/p/14276811.html