1、变更项目结构

2、新增说明文档
This commit is contained in:
TianJun
2021-04-29 12:45:56 +08:00
parent 8ec36e0028
commit f6fc4ea83c
14 changed files with 44 additions and 35 deletions
+65
View File
@@ -0,0 +1,65 @@
package v1
import (
"fmt"
"github.com/gin-gonic/gin"
)
type Student struct {
ID uint `json:"id"`
Username string `json:"username"`
Age uint `json:"age"`
}
func DescribeStudents(c *gin.Context) {
var students []Student
c.JSON(200, gin.H{
"data": students,
"page": 1,
"pageSize": 15,
})
}
func DescribeStudentById(c *gin.Context) {
id := c.Params.ByName("id")
fmt.Println("id=", id)
var student Student
if student.ID == 0 {
c.JSON(404, gin.H{"message": "student not found"})
return
}
c.JSON(200, student)
}
func CreateStudent(c *gin.Context) {
var student Student
// 绑定一个请求主体到一个类型
_ = c.BindJSON(&student)
c.JSON(200, "创建成功")
}
func ModifyStudentById(c *gin.Context) {
id := c.Params.ByName("id")
fmt.Println("id=", id)
var student Student
if student.ID == 0 {
c.JSON(404, gin.H{"message": "student not found"})
return
} else {
_ = c.BindJSON(&student)
c.JSON(200, student)
}
}
func DeleteStudentById(c *gin.Context) {
id := c.Params.ByName("id")
fmt.Println("id=", id)
var student Student
if student.ID == 0 {
c.JSON(404, gin.H{"message": "student not found"})
return
} else {
_ = c.BindJSON(&student)
c.JSON(200, gin.H{"message": "delete success"})
}
}