han-joker 2 years ago
parent a721a9f3bd
commit 2945a5d744

@ -0,0 +1,25 @@
package main
import (
"github.com/gin-gonic/gin"
"simpleCms/app/content"
)
// 声明一个main包level的变量
var router = gin.Default()
// init 初始化时执行用于完成API的定义
func init() {
// 定义任意的uri,api
router.GET("/content/:id", content.Get)
router.DELETE("/content/:id", content.Delete)
router.PUT("/content/:id", content.Put)
router.POST("/content", content.Post)
router.GET("/ping", func(c *gin.Context) { // &
//c.Query("")// ?name=xx
c.JSON(200, gin.H{
"message": "pong",
})
})
}

@ -0,0 +1,31 @@
package content
// controller
import (
"github.com/gin-gonic/gin"
"net/http"
)
// action
func Get(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"id": ctx.Param("id"),
"message": "内容查询",
})
}
func Post(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"message": "内容添加",
})
}
func Delete(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"message": "内容删除",
})
}
func Put(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"message": "内容更新",
})
}
Loading…
Cancel
Save