在这里插入图片描述

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",
	})
}

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部