macbook golang zsh: exec format error

On the Mac computer, compile the code of golang. After the code is successfully compiled, execute it. An error is reported

exec format error

After a long time of investigation, I finally found the problem: my computer’s configuration of golang is as follows:

GOOS="linux"

After compiling, I run it on MacOS, so I report an error.

When you know where the problem is, it’s very easy to solve it. When compiling, the execution is as follows:

GOOS=darwin GOARCH=amd64 go build -o  http -v ./main.go

Read More: