Go Package installed but not able to import

1k Views Asked by At

Not able to import the gorilla/mux package even though it is installed. i used the command "go get github.com/gorilla/mux" to install the package which installed the package under the pkg directory as per the GOPATH as below.

C:\Users*\go;C:\Users*\goProject

But as go Looks for the packages in the src directory, i moved the Gorilla package to the folder "C:\Users*\goProject\src" folder and removed the go.mod file. After that i initialized the package bu executing the command "go mod init" but still import fails.

Please find below the snap shot . Can anyone please help with this issue.

enter image description here

Solution for the above issue

1

There are 1 best solutions below

0
hmmftg Stands with Palestine On

Hi if your project is small and only has one package(few files in the same folder which are in the same scope) please follow these steps:

  1. create an empty folder for your project
  2. run this command: go mod init main instead of main you can put your project name or URL
  3. add your files and run go mod tidy, at this step the packages you use(for your case gorrila/mux) are downloaded and ready to use
  4. now you can run your app by go run main

for more advanced projects, you can follow 1 and 2 step and then create folders for your desing and have multiple main packages in separate folders and create multiple executable binaries, if you need more details you are welcome to ask