The best way to count the number of spaces before the first non-space character
of a string in Go is by using the
strings.TrimLeft function as shown below:
countLeadingSpaces function above trims all the leading space characters
from the original string and subtracts the length of the result from the length
of the original to derive the number of leading spaces.
Another option is to iterate over each character in the string and increment a counter until the first non space character is encountered:
Thanks for reading, and happy coding!