How to Fix unexpected directory layout in go language

1. Make sure the path is set correctly </h2 b> There is a problem with the directory structure of the

project. Suggested structure:

  - bin (可不需要)
  - src
    - sub-project-1
      - module1
      - module2
      - vendor
    - sub-project-2 
  - pkg (可不需要)

and appends the project directory to the environment variable GOPATH. Only one path

is saved in GOPATH

vim /etc/profile
export GOPATH=/root/go
export GOROOT=/usr/lib/golang
export PATH=$GOPATH/bin:$PATH
source /etc/profile

2. Check to see if there are duplicate folders </h2 b>

in the centos directory, or GOROOT directory, it was found that SRC/had the same directory file as the project in GOPATH, after deleting it and recompiling the project in GOPATH, the problem was solved. Where XXX stands for compilation engineering project.

rm -rf /usr/lib/golang/src/XXX


Read More: