轻量级web框架
eg:
package main
import (
"github.com/gin-gonic/gin"
"net/http"
)
type msg struct{
Name string `json:"name"`
Message string
Age int
}
func main(){
r := gin.Default()
r.GET("/json", func(c *gin.Context) {
//方法1:使用map
//data := map[string]interface{}{
// "name":"麻衣",
// "message":"hello world",
// "age":"18",
//}
data := gin.H{"name":"麻衣","message":"hello world!","age":18}
c.JSON(http.StatusOK,data)
})
r.GET("/someJSON", func(c *gin.Context) {
c.JSON(http.StatusOK,gin.H{"message":"hello world!"})
})
r.GET("/moreJSON", func(c *gin.Context) {
data2 := msg{
Name: "晏明宇",
Message: "fuck",
Age: 18,
}
c.JSON(http.StatusOK,data2)
})
r.Run(":9090")
}