I'm learning to write Golang makefile and got some confused me because some examples they config GO env such as GOOS, GOPATH, GOBASE
before building. But normally I can use go mod init
to create go module and in Makefile use go build
to build my project.
So what's is the best approach ?
Asked
Active
Viewed 722 times
-1

Quang
- 135
- 2
- 9
-
5If you have a choice - use `go mod`. GOPATH builds are considered legacy. – colm.anseo Sep 11 '20 at 00:31
1 Answers
0
Modern go
code with go mod
. Makefile
should not include GOPATH
. Just use go build
is enough.

Ming C
- 2,476
- 2
- 14
- 8
-
In Makefile, using `go build` without `go mod init projectName` ahead gives me an error: `go: cannot find main module` But If I include `go mod init ProjectName` and `go mod tidy`, I cannot `make build` multiple times because the following build will try to do `go mod init` again, which is not allowed. I wonder what is the best practice of writing a Makefile for a Go project – yeehaw Oct 24 '21 at 04:24