package main
import (
"fmt"
"github.com/gin-gonic/gin"
"io/ioutil"
"net/http"
)
func main(){
router:=gin.Default()//默认绑定 中间件gin.Logger(), gin.Recovery()
router.GET("/v1",get)
router.POST("/v1/:name",post)
router.Run("127.0.0.1:8080")
}
func get(c *gin.Context){
c.JSON(http.StatusOK,"********************")
}
func post(c *gin.Context){
name:=c.Param("name")//获取url中的参数
//messages:=c.PostForm("message")//获得以 application/x-www-form-urlencoded或from-data格式 提交的参数
//fmt.Println(messages)
body,_:=ioutil.ReadAll(c.Request.Body)//获得以 application/json 提交的参数
fmt.Println(string(body))
c.JSON(http.StatusOK,gin.H{"status":"receive","name":name})
}