package main
import (
"github.com/gin-gonic/gin"
"net/http"
)
func main() {
route := gin.Default()
v1 := route.Group("v1") // 分组
{
v1.GET("/server1", func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"path": "/v1/server1",
})
})
v1.GET("server2", func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"path": "/v1/server2",
})
})
}
v2 := route.Group("v2")
{
v2.GET("/server1", func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"path": "/v2/server1",
})
})
v2.GET("server2", func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"path": "/v2/server2",
})
})
}
err := route.Run(":8080")
if err != nil {
panic(err)
}
}