I am trying to install the net package for go but get "does not contain package error".
Terminal screenshot:
I have consulted: go module @latest found but does not contain package but none of the solutions seem to work for me.
I am using go version go1.18.5 linux/amd64
CodePudding user response:
go get -u golang.org/x/net
go install used for executable packages
CodePudding user response:
You have to initialize your module with go mod init
in the project root directory
For local codebase
go mod init test
OR for hosted codebase e.g. github repo: test, github user: radiant
go mod init github.com/radiant/test
It will produce a go.mod
file.
Then you can get the required package as:
go get golang.org/x/net
go mod tidy
Then import and use the net packages.
Hope this helps.