Home > Blockchain >  My go web server won't build when I do go build, it says package is not in goroot (or gopath) e
My go web server won't build when I do go build, it says package is not in goroot (or gopath) e

Time:10-07

I have a go server repository then cloned it to linux system in folder /var/www/develop/project.id. It has several folders with each folders have their own go file(s). The main.go is located in folder/subfolder/main.go. In each go files, if I need to import go files from another folder, I do:

import myproject/foldername/subfoldername

Then in the root project, I do:

go mod init myproject
go mod tidy
go build -o main folder/subfolder/main.go

But I failed at the build step because package myproject/foldername/subfoldername is not in GOROOT (/usr/local/go/src/myproject/foldername/subfoldername).

Any help on solving this problem? Thank you.

UPDATE: I lose my mind, I can’t make it work. It works everywhere else (on windows) but it’s just not work for this particular project (multiple folders same inside) on Linux but it works on a different project.

CodePudding user response:

It looks like you are missing the go.mod file. Run the command go mod init myproject to create the go.mod file. Notice that mod and init are swapped in the command that you ran.

CodePudding user response:

every files like xx.go always need 'main.go',unless 'go build' it separated.

  •  Tags:  
  • go
  • Related