4、代码
package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
如果 import “github.com/gin-gonic/gin” 爆红,解决办法如下:
go mod init gin
go mod edit -require github.com/gin-gonic/gin@latest
go mod vendor