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 user
import (
"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",
})
}
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » gin路由
发表评论 取消回复