# 理论步骤 mkdir -p $GOPATH/src/github.com/afeiship/gin_test_project cd $_ go mod init go get -v github.com/gin-gonic/gin@v1.4 # 我的实操作 cd /Users/aric.zheng/go/src/github.com/gin-get-started go mod init go get -v github.com/gin-gonic/gin@v1.4
❯ tree . ├── README.md ├── go.mod ├── go.sum └── start └── main.go 1 directory, 4 files
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() }
❯ curl localhost:8080/ping {"message":"pong"}