下载1.19 go :https://go.dev/dl/go1.19.2.linux-amd64.tar.gz

解压缩:tar zxvf go1.19.1.linux-amd64.tar.gz

修改配置文件:(source ~/.bashrc)
~/.bashrc

138 export GOROOT=/workspace/coding_tools/go/go #golang安装目录
139 export GOPATH=$HOME #gopath
140 export GOBIN=$GOROOT/go/bin                 #go编译可执行文件

把文件夹的1.18删除了,解压缩了1.19,然后安装gin

创建文件:

package main
import (<br />
&nbsp; &quot;net/http&quot;
&nbsp; &quot;github.com/gin-gonic/gin&quot;<br />
)
func main() {<br />
&nbsp; r := gin.Default()<br />
&nbsp; r.GET(&quot;/ping&quot;, func(c *gin.Context) {<br />
&nbsp;&nbsp;&nbsp; c.JSON(http.StatusOK, gin.H{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;message&quot;: &quot;pong&quot;,<br />
&nbsp;&nbsp;&nbsp; })<br />
&nbsp; })<br />
&nbsp; r.Run() // listen and serve on 0.0.0.0:8080 (for windows &quot;localhost:8080&quot;)<br />
}
# run example.go and visit 0.0.0.0:8080/ping (for windows &quot;localhost:8080/ping&quot;) on browser<br />
$ go run example.go