The example below shows to how to encode and then subsequently decode a string using base 64. Doing this has many uses, one of which to safely encode byte data in structures like JSON.
We use the
encoding/base64 package to do this, which takes in and returns a byte array into it’s
DecodeString methods. These functions differ in the fact that only the decode returns an error you will need to handle.