Problem

When we use golang to get required dependencies or packages ,sometimes ,we get this error:

➜  k8s-operator-helloworld go get 

go get .: cannot find package

The core error is :

go get .: cannot find package

Environment

  • MacOS 10.14
  • Golang go version go1.14 darwin/amd64

Reason

Go get command is as follows:

UsageLine: "go get [-d] [-f] [-t] [-u] [-v] [-fix] [-insecure] [build flags] [packages]",
Short:     "download and install packages and dependencies"
    
Get downloads the packages named by the import paths, along with their
dependencies. It then installs the named packages, like 'go install'.

You should specify what to get , or else, it would complain.

Solution

We should use go get like this: (Execute the following command in the current project and tell it to find all required packages recursively by using this command)

go get -u ./...

The -u flag instructs get to use the network to update the named packages and their dependencies. By default, get uses the network to check out missing packages but does not use it to look for updates to existing packages.

Or you can get all required packages for current package:

go get all