1. 程式人生 > 其它 >golang第三方模組gin安裝執行

golang第三方模組gin安裝執行

開啟gomodule:

[root@iZbp1iv9qz41r73ax80ihpZ hello]#go run .\demo04.go
demo04.go:4:2: cannot find package "github.com/gin-gonic/gin" in any of:
··········
($GOPATH not set. For more details see: 'go help gopath')
[root@iZbp1iv9qz41r73ax80ihpZ hello]# go env -w GO111MODULE=on
[root@iZbp1iv9qz41r73ax80ihpZ hello]# go env -w GOPROXY=https://goproxy.cn

生成go.mod檔案:

[root@iZbp1iv9qz41r73ax80ihpZ hello]# go run hello.go
hello.go:4:2: no required module provides package github.com/gin-gonic/gin: go.mod file not found in current directory or any parent directory; see 'go help modules'
[root@iZbp1iv9qz41r73ax80ihpZ hello]# go mod init hello
go: creating new go.mod: module hello
go: to add module requirements and sums:
go mod tidy
[root@iZbp1iv9qz41r73ax80ihpZ hello]# ls


go.mod hello.go
[root@iZbp1iv9qz41r73ax80ihpZ hello]# go get -u github.com/gin-gonic/gin
go: downloading github.com/mattn/go-isatty v0.0.12
go: downloading github.com/go-playground/validator/v10 v10.4.1
go: downloading github.com/go-playground/validator/v10 v10.10.0
go: downloading github.com/go-playground/validator v9.31.0+incompatible
go: downloading github.com/golang/protobuf v1.3.3
go: downloading github.com/ugorji/go v1.1.7
go: downloading github.com/ugorji/go/codec v1.1.7
go: downloading gopkg.in/yaml.v2 v2.2.8
go: downloading github.com/json-iterator/go v1.1.9
go: downloading github.com/json-iterator/go v1.1.12
go: downloading golang.org/x/sys v0.0.0-20200116001909-b77594299b42
go: downloading golang.org/x/sys v0.0.0-20220209214540-3681064d5158
go: downloading github.com/go-playground/universal-translator v0.17.0
go: downloading github.com/leodido/go-urn v1.2.0
go: downloading golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
go: downloading golang.org/x/crypto v0.0.0-20220210151621-f4118a5b28e2
go: downloading github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421
go: downloading github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
go: downloading github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742
go: downloading github.com/modern-go/reflect2 v1.0.2
go: downloading github.com/go-playground/locales v0.13.0
go: downloading golang.org/x/text v0.3.6
go: downloading google.golang.org/protobuf v1.26.0
go get: added github.com/gin-gonic/gin v1.7.7
go get: added github.com/go-playground/validator/v10 v10.10.0
go get: added github.com/golang/protobuf v1.5.2
go get: added github.com/json-iterator/go v1.1.12
go get: added github.com/mattn/go-isatty v0.0.14
go get: added github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
go get: added github.com/ugorji/go v1.2.6
go get: added golang.org/x/crypto v0.0.0-20220210151621-f4118a5b28e2
go get: added golang.org/x/sys v0.0.0-20220209214540-3681064d5158
go get: added golang.org/x/text v0.3.7
go get: added google.golang.org/protobuf v1.27.1
go get: added gopkg.in/yaml.v2 v2.4.0
[root@iZbp1iv9qz41r73ax80ihpZ hello]# go run hello.go

[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET /ping --> main.main.func1 (3 handlers)