安装gin
在命令行下执行安装 (推荐学习:go)
go get -u github.com/gin-gonic/gin
检查/usr/local/go/path中是否存在gin的代码包
测试gin是否安装成功
编写一个test.go文件
package mainimport "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}
执行test.go
go run test.go
访问$host:8080/ping,若返回{"message":"pong"}则正确
curl 127.0.0.1:8080/ping
至此,我们的环境安装都基本完成了:)
以上就是golang gin怎么安装的详细内容。