1主文件
package main
import ("github.com/gin-gonic/gin""godade/user""net/http"
)
func main() {router := gin.Default()router.GET("/", func(c *gin.Context) {c.String(http.StatusOK, "Hello World")})v1 := router.Group("/v1"){v1.GET("/user", user.UserGetHandler)}v2 := router.Group("/v2"){v2.GET("/dade", user.UserGetHandler)}router.GET("/user/dade", user.UserPostHandler)router.Run("0.0.0.0:8000")
}
2子文件
package userimport ("github.com/gin-gonic/gin"
)func UserGetHandler(c *gin.Context) {c.JSON(200, gin.H{"message": "This is the user get route",})
}func UserPostHandler(c *gin.Context) {c.JSON(200, gin.H{"message": "This is the user post route",})
}