-3

Suppose I have main.go in directory project/ and have subdirectory project/pkg/mydb/ that is used by main.go.

To add a dependency to my code inside mydb/ I should run go get ... in that subdir mydb/ or in top-level project directory (project/)?

Also where main.go should reside: directly in project/ or in project/src/?

porton
  • 5,214
  • 11
  • 47
  • 95
  • 1
    Please read https://go.dev/doc/, especially the Tutorials which explain exactly this. Use modules. – Volker Jun 01 '22 at 08:37

1 Answers1

2

Go only think in term of module and packages. Usually your module would be project/ and can be composed of one or several packages (project/pkg/mydb can be one of them)

Only go modules have dependencies. So you should run go get in project

main.go can be wherever you want, it will just change whether you need to run go build . or go build ./src

(This is only applicable if you use go modules, so if you have a go.mod in your project. But if you should be using them anyway)

aureliar
  • 1,476
  • 4
  • 16