1. 创建一个 Go Modules 项目 创建目录 1 2 mkdir go-test cd go-test 初始化包 1 2 3 4 5 go mod init gitlab.private.com/shaowenchen/go-test go: creating new go.mod: module gitlab.private.com/shaowenchen/go-test go: to add module requirements and sums: go mod tidy 添加业务代码 main.go 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 package main import ( "github.com/gin-gonic/gin" ) func main() { r := gin.Default() r.GET("/", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "hello world.", }) }) r.Run() } 下载依赖到 vendor 1 2 go mod tidy go mod vendor 本地运行 1 2 3 4 5 go run