package main
import (
"github.com/gin-gonic/gin"
"net/http"
)
type Response struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
}
type User struct {
ID int
Name string
}
func main() {
r := gin.Default()
r.GET("/user", getUser)
r.Run(":8888")
}
func getUser(context *gin.Context) {
users := []User{{ID: 123, Name: "jony"}, {ID: 1, Name: "konle"}}
res := Response{
200,
"success",
users,
}
context.JSON(http.StatusOK, res)
}
记录两点自己一开始不知道的
网友评论