The go language sets how to set the project folder when there are multiple projects in gopath,?

the go language sets how to set the project folder when there are multiple projects in gopath,?

the environment variable is set as follows:

, which is installed on go 1.11, which is installed on windows.
GOROOT  D:\workspace\go  
PATH    D:\workspace\go\bin
GOPATH  D:\workspace\www\go_work    //GOPATHGOROOT
Under the

go_work folder, there are bin , pkg , and src three directories.

question:
if there are multiple projects, such as project_01 , project_02 , project_03 , where should I put these three project folders?

Nov.05,2021


go1.11, which used to be placed under the src folder, supports go modules, and you can put it as long as it's not in the gopath directory.
if you do it the old way: put it under src
with the new one: casually put it, and then use go mod init
both ways I used on the project. Generally speaking, go mod is a bit crappy now, but this is the trend of the future.


the traditional way is to put it in the src directory. Take Chestnut, your GOPATH is D:\ workspace\ www\ src\ go_work, then your project should create a new directory D:\ workspace\ www\ src\ go_work\ project_01,D:\ workspace\ www\ src\ go_work\ project_02. Suppose the structure within project_01 is

  • main.go
  • file1

    • file1.go (package file1)

assume that the structure within the project_02 is

  • main.go
  • file2

    • file1.go (package file2)

then if you want to quote project_02 's package file2, in project_01, you should write import project_02/file2

.
The

project should be put like this, and the second layer is full of project names:

  go tree -L 2 $GOPATH/src
/Users/xxxxx/go/src
 github.com
  Masterminds
  cweill
  davidrjenni
  tendermint
  uudashr
 golang.org
  x
 gopkg.in
  bsm
  redis.v4
  yaml.v2
 govendor
  LICENSE
  README.md
  appveyor.yml
  cliprompt
  context
  doc
  help
  internal
  main.go
  migrate
  pkgspec
  prompt
  run
  vcs
  vendor
  vendorfile
 sourcegraph.com
     sqs
Menu