Monday, May 20, 2024
HomeGolangWhat does this syntax imply in go? - Getting Assist

What does this syntax imply in go? – Getting Assist


How/when are these variables used?

I got here throughout one instance right here:

fmt.Println(base64.StdEncoding.EncodeToString([]byte(“consumer:go”)))

base64 is a package deal
StdEncoding is a variable
EncodeToString is a perform.

I’ve a normal understanding what is occurring right here and what the tip result’s, but when I needed to write this myself, I might be caught since I dont perceive the main points.

Hello, @vinayak.vg, Are you able to elaborate extra on what you imply by not understanding the main points? Your description of what’s taking place sounds right to me.

Within the meantime, I’ll make an assumption that you’re referring to how a lot “stuff” is occurring in a single line of code right here in comparison with how a lot you might really feel that there must be. I used to write down code like this, myself, maybe to a better extent in C#, however then I began including intermediate variables simply in order that I can provide issues names, like this:

username := "consumer"
password := "go"
rawBasicAuthString := username + ":" + password
base64Encoding := base64.StdEncoding
encodedBasicAuthString := base64Encoding.EncodeToString([]byte(rawBasicAuthString))
fmt.Println(encodedBasicAuthString)

I feel when you break the expression aside, it turns into clearer what’s occurring.

If this isn’t what you imply, then please let me know.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments