Thursday, March 16, 2023
HomeGolangWhat does this phrase structure mean in go? - Obtaining Assistance

What does this phrase structure mean in go? – Obtaining Assistance

How/when are these variables made use of?

I found one instance below:

fmt.Println( base64.StdEncoding.EncodeToString([] byte(” customer: pass”)))

base64 is a plan
StdEncoding is a variable
EncodeToString is a feature.

I have a basic understanding what is taking place below and also what completion outcome is, however if I needed to create this myself, I would certainly be stuck given that I do not comprehend the information.

Hi, @vinayak. vg, Can you clarify a lot more on what you imply by not comprehending the information? Your summary of what’s taking place audios right to me.

In the meanwhile, I will certainly make a presumption that you are describing just how much “things” is taking place in a solitary line of code below contrasted to just how much you might really feel that there need to be. I made use of to create code similar to this, myself, possibly to a higher degree in C#, however after that I began including intermediate variables so that I can provide points names, similar to this:

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

I believe when you damage the expression apart, it comes to be more clear what’s taking place.

If this isn’t what you imply, after that please allow me recognize.

1 Like

Thanks @skillian for the description.
I am attempting to comprehend some basics below.
when I kind base64, the intellisense in vscode begins and also I obtain ideas for approaches, variables, continuous inside the base64 bundle.
i see that there are 4 variables in this bundle ( RawStdEncoding, RawURLEncoding, StdEncoding, URLEncoding). Every one of them recommend me that I can utilize the very same features adhering to the variable (intellisense begins once more). I wish to know what these variables imply and also what is their importance.

Tldr: I comprehend ideas for approaches and also constants. I do not comprehend the variable component.

The variables are clarified in the docs:

1 Like

The variables in the bundle are much like variables in your very own code. You could, for instance, usage base64.NewEncoding to produce your very own base-64 alphabet:

 bundle major.

import (.
" encoding/base64".
" fmt".
" os".

var myQueryEncoding = base64.NewEncoding(" 1234567890-qwertyuiopasdfghjklzxcvbnm ~ _ QWERTYUIOPASDFGHJKLZXCVBN").

func major() {
fmt.Prinln( myQueryEncoding.EncodeToString( os.Args[1])).

When you key in myQueryEncoding., you obtain the very same ideas as VS Code would certainly provide you when you key in base64.StdEncoding., since they’re both variables with the very same kinds ( * base64.Encoding), therefore they have the very same approaches.

1 Like

Perfect @skillian Many thanks a lot. I kinda obtained wandered from the basics while discovering more sophisticated subjects. There is factor they are called “variables”. There are several methods to accomplish inscribing and also we can utilize what we desire based upon our demands, prior to we can call the EncodeToString feature. Many thanks once more

This subject was instantly shut 90 days after the last reply. New replies are no more permitted.


Most Popular

Recent Comments