const foobar = `foo bar` encoding := base64.StdEncoding encodedFooBar := make([]byte, encoding.EncodedLen(len(foobar))) encoding.Encode(encodedFooBar, []byte(foobar)) fmt.Printf("%s", encodedFooBar) // Output: Zm9vIGJhcg==
Playground