Go(Golang) build,mind blown
Table of Contents
Build go app really easy just:
go build -o named_out_put program.go
You can run the command without program.go
if your go program is call main.go
And for more, it support cross platform compile natively!
Like I do my development on my Macbook M2 which is arm64 platform. If we run above go build command, go default compile in my machine which is support arm64 only.
If we deploy the compiled program to x86 linux, it will not success to run the program. But! we can fix this just only add some arguments with build command:
For target to linux x86:
GOOS=linux GOARCH=amd64 go build -o named_out_put program.go
Then you can free to run the program on linux server without any go env and dependency!
It was shock me, it just easy to use and totally 0 configuration.Just one code file then can build to any platform like linux, windows, macos, even android!
1. Golang trap
variable reassign issue
func main() { count := 0 if count < 5 { count := 10 count++ } fmt.Println(count == 11) // result is false }
Here, the trap is the count
at the end is 0…