go env -w GOPROXY=https://goproxy.cn,direct
go mod init api
go get -u github.com/gin-gonic/gin
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
func main() {
fmt.Println("start---->")
run()
}
func run() {
r := gin.Default()
r.GET("/test", func(c *gin.Context) {
c.JSON(200, gin.H{
"data": "success",
})
})
r.GET("/query", func(c *gin.Context) {
name := c.DefaultQuery("name", "taoqun")
age := c.Query("age")
c.JSON(200, gin.H{
"name": name,
"age": age,
})
})
fmt.Println("http://localhost:8080")
r.Run()
}