赞
踩
获得头信息
router.GET("/", func(c *gin.Context) {
name := c.Query("id")
fmt.Println(name)
Token := c.GetHeader("Token")
c.JSON(http.StatusOK, Token)
})
获得get和post信息
package main
import (
"fmt"
"github.com/SimonWang00/goeureka"
"github.com/gin-gonic/gin"
"net/http"
)
type Dades struct {
Id int
Name string
Age int
}
func main() {
router := gin.Default()
router.GET("/", func(c *gin.Context) {
//获得get数据
name := c.Query("id")
fmt.Println(name)
c.String(http.StatusOK, "Hello World")
})
router.POST("/", func(c *gin.Context) {
//获得json格式提交的数据
var data map[string]interface{}
c.BindJSON(&data)
c.JSON(http.StatusOK, data)
})
router.Run("0.0.0.0:8000")
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。