1. 程式人生 > 其它 >'go get' is no longer supported outside a module.

'go get' is no longer supported outside a module.

準備下載一個gin框架,執行go get報錯如下

PS D:\work\10_Git\pulse-src> go get -u github.com/gin-gonic/gin
go: go.mod file not found in current directory or any parent directory.
        'go get' is no longer supported outside a module.
        To build and install a command, use 'go install' with a version,
        like 
'go install example.com/cmd@latest' For more information, see https://golang.org/doc/go-get-install-deprecation or run 'go help get' or 'go help install'. go: cannot find main module, but found .git/config in D:\work\10_Git\pulse-src to create a module there, run: go mod init

 

官方說字1.17之後,不應該用go get下載安裝命令(即可執行程式),如果使用goget安裝命令,就會提示上述警告,

也就是說go get只能下載普通的包,如果下載安裝程式需要用go install

PS D:\work\10_Git\pulse-src> go install github.com/gin-gonic/gin@v1.7.7
go: downloading github.com/gin-gonic/gin v1.7.7
go: downloading github.com/gin-contrib/sse v0.1.0
go: downloading github.com/mattn/go-isatty v0.0.12
go: downloading github.com/golang/protobuf v1.3.3 go: downloading github.com/ugorji/go/codec v1.1.7 go: downloading gopkg.in/yaml.v2 v2.2.8 go: downloading github.com/go-playground/validator/v10 v10.4.1 go: downloading golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 go: downloading github.com/go-playground/universal-translator v0.17.0 go: downloading github.com/leodido/go-urn v1.2.0 go: downloading github.com/ugorji/go v1.1.7 go: downloading github.com/go-playground/locales v0.13.0 package github.com/gin-gonic/gin is not a main package PS D:\work\10_Git\pulse-src>