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

2020-07-06  本文已影响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()
}
上一篇下一篇

猜你喜欢

热点阅读