美文网首页
简单接口

简单接口

作者: 上帝死了众神在堕落 | 来源:发表于2022-05-19 11:55 被阅读0次
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)
}

记录两点自己一开始不知道的

相关文章

网友评论

      本文标题:简单接口

      本文链接:https://www.haomeiwen.com/subject/ntltprtx.html