Golang-如何在工作区中定义多个项目

The GOPATH in Go points to the workspace. Can I create multiple projects in my workspace and have GOPATH point to a list of the locations of these projects?

You can use single workspace but if you want to work with another project out of workspace, you should check your imports. Because when you import golang packages

import "fmt"

It searchs "fmt" package on GOROOT or other packages which is get via

go get github.com/package

It puts package under %workspace(GOPATH)%\src\github.com. It doesn't put package under your project. So you can clone 3rd party projects under your project folder and set imports like relative path notation:

import "./github.com/package"

then run your go files. It works.

Yes you can have multiple projects in your workspace. However, you do not specify multiple GOPATHs for that. You simply create your two projects within that GOPATH environment. And to compile, run etc you simply specify the entry point you want to use.

E.g.

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

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

Specifically, “src contains Go source files organized into packages (one package per directory),”. Notice that you are not limited to only one main package.