美文网首页
Gin-返回数据-返回struct类型

Gin-返回数据-返回struct类型

作者: 诗意_面包 | 来源:发表于2020-07-06 14:41 被阅读0次
package main

import (
    "github.com/gin-gonic/gin"
    "net/http"
)

type Student struct {
    Name string
    Age int
}

func main()  {
    app := gin.Default()
    app.Handle("GET", "/", func(context *gin.Context) {
        var student Student
        student.Name = "王二狗"
        student.Age = 18
        context.JSON(http.StatusOK, &student)
    })
    app.Run()
}

相关文章

网友评论

      本文标题:Gin-返回数据-返回struct类型

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