初始

package main

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

type Topic struct {
    TopicID int
}


func main() {
    m := make(map[string]interface{})
    m["username"] = "jerry"
    router := gin.Default()
    router.GET("/", func(context *gin.Context) {
        context.Writer.Write([]byte("hello"))
        context.JSON(http.StatusOK, Topic{2})//gin支持直接用map去传递json
           context.JSON(http.StatusOK, gin.H{"hello":"world"})//也可以用gin.H去传递自定义的json

    })
    router.Run()
}




原文地址:https://www.cnblogs.com/hualou/p/12071051.html