I came up with a way to pad leading zeros into a Go string. I'm not sure if this is the way you do this in Go. Is there a proper way to do this in Go? This is what I came up with and can be found inside the second if block. I tried Google to see if it had something built in without luck.
func integerToStringOfFixedWidth(n int, w int) string {
s := strconv.Itoa(n)
l := len(s)
if l < w {
for i := l; i < w; i++ {
s = "0" + s
}
return s
}
if l > w {
return s[l-w:]
}
return s
}
For n = 1234 and w = 5, the output should be integerToStringOfFixedWidth(n, w) = "01234".