package main import ( "fmt" "github.com/gin-gonic/gin" ) func main() { r := gin.Default() //路由组:处理GET请求 v1 := r.Group("/v1") //{}是书写规范 { v1.GET("/login", login) v1.GET("/submit", submit) } v2 := r.Group("/v2") { v2.POST("/login", login) v2.POST("/submit", submit) } r.Run(":8000") } func login(c *gin.Context) { name := c.DefaultQuery("name", "Jack") c.String(200, fmt.Sprintf("hello:%s", name)) } func submit(c *gin.Context) { name := c.DefaultQuery("name", "lily") c.String(200, fmt.Sprintf("hello:%s", name)) }