Gin返回结构体

package main

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

type info struct {
	Name string   `json:"name"`
	Age  int      `json:"age"`
	Like []string `json:"like"`
}

func processJson(ctx *gin.Context) {
	qian := info{
		Name: "qian",
		Age : 18,
		Like: []string{
			"smoking",
			"drinking",
			"perm",
		},
	}

	ctx.JSON(http.StatusOK, qian)
}

func main() {
	r := gin.Default()

	r.GET("/json", processJson)

	err := r.Run(":8080")
	if err != nil {
		fmt.Println(err)
		return
	}
}

Gin返回结构体

Gin返回结构体

上一篇:LeetCode(剑指 Offer)- 题集


下一篇:剑指 Offer 10- II. 青蛙跳台阶问题