package main
import (
"fmt"
"github.com/gin-gonic/gin"
"net/http"
"strconv"
)
type info struct {
Name string `json:"name"`
Age int `json:"age"`
Like []string `json:"like"`
}
func processJson(ctx *gin.Context) {
age,_ := strconv.Atoi(ctx.Query("age"))
data := info{
Name: ctx.Query("name"),
Age : age,
Like: ctx.QueryArray("like"),
}
ctx.JSON(http.StatusOK, data)
}
func main() {
r := gin.Default()
r.GET("/json", processJson)
err := r.Run(":8080")
if err != nil {
fmt.Println(err)
return
}
}
Gin获取请求参数