-2

I am starting in Golang development. Right now my boss gave me the repository of a project that other developer made, now he's gone of the company and I am not able to ask him some things related to it. Right now I have a confussion about the project structure that he pushed to the repo, the structure is the next:

 |-MyApp
 |--bin
 |--pkg
 |--src
 |----api (the code of the app)
 |----github.com
 |----golang.org
 |----gopkg.in

To me, it's exaclty as the estructure of the Go, 1.- in the repo should not be only the api folder? If I go to the api folder and make go run main.go I get a message that some packages are not found even when they are in the folder, 2.-how I specify the packages in the go run command?

3.- Is a good practice to set this kind of structure for the golang projects? I see in the code that he exported the packages only with "package1", if I copy and paste the code of the app inside the golang workspace then I have to specify the name of the folder to export the packages, example: "myApp/package1" so there I have that doubt. Thank you

Sredny M Casanova
  • 4,735
  • 21
  • 70
  • 115
  • Possible duplicate of [Organizing a multiple-file Go project](https://stackoverflow.com/questions/9985559/organizing-a-multiple-file-go-project) – Jonathan Hall Jun 25 '17 at 13:20

1 Answers1

2

That all depends. There is not a single right way for everything.

It seems as if this repo decided to vendor everything, the whole GOPATH. That is okay but with the "modern" vendor folder today one would do it probably differently.

Never do go run. That's for toy programs only. Build your software with go build and go install. These command work on package path.

For everything else: Please see the official documentation https://golang.org/doc/code.html and stick to it (which means you should move stuff around a bit).

Volker
  • 40,468
  • 7
  • 81
  • 87