-1

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 ?

Quang
  • 135
  • 2
  • 9

1 Answers1

0

Modern go code with go mod. Makefile should not include GOPATH. Just use go build is enough.

see https://blog.golang.org/using-go-modules

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