Golang - How to Define Multiple Projects in a Workspace

GOPATH in Go indicates a workspace. Can I create several projects in my workspace and specify GOPATH in the list of locations of these projects?

+7
go
source share
2 answers

Yes, you can have several projects in your workspace. However, several GOPATH not indicated for this. You simply create your two projects in this GOPATH environment. And for compilation, launch, etc. You simply specify the entry point you want to use.

eg.

 go run src/proj1/proj1.go go run src/proj2/proj2.go 

For more information about GOPATH and workspaces, see godoc on workspaces .

In particular, "src contains Go source files organized in packages (one package for a directory)." Please note that you are not limited to just one core package.

+2
source share

You can use one workspace, but if you want to work with another project from the workspace, you should check your import. Because when you import golang packages

 import "fmt" 

He is looking for the "fmt" package on GOROOT or other packages that get through

 go get github.com/package 

It places the package under %workspace(GOPATH)%\src\github.com . It does not put a package under your project. Thus, you can clone third-party projects in the project folder and set the import as a relative path entry:

 import "./github.com/package" 

then run your go files. He works.

0
source share

All Articles