Home > Mobile >  Directory layout and `got get ...` for Go language
Directory layout and `got get ...` for Go language

Time:06-02

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/?

CodePudding user response:

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)

  • Related