Reduce Go Binary Size
Always a hot-topic in Go circles is binary size of applications. In this post we will show you how you can reduce the binary size produced from go build for leaner, slimer builds. In short, adding the ldflags shown below will reduce the size of the binary produced. It does this by removing some perhaps non-critial parts (shouldn’t affect execution, only debugging potentially). -s Will turn off the symbol table, so you won’t be able to use commands like go tool nm.
Find the Length of an Array
You can find the length of an array, or to be correct a slice or map, in Go by using the standard library function len(). We use the term array loosely here, as a general variable holding multiple things. Maps tend to have defined keys, whereas slices don’t (more info on the difference here). We have shown both as examples below, how to get the length of a slice and how to get the length of a map.