Hello and welcome to the Golang programming language course.
In the previous session, we talked about A. In their face time and in this session, we want to talk
about the others interface concept.
Access underlying variable of interface down the line variable can be accessed in two ways.
First type assertion and second type switch.
Type assertion provides a way to access the underlying variable inside the inner face value of the interface
by asserting the correct type of underlying value and types, which enables us to do above time assertion
in serious.
Type assertions.
In Go language type assertion is an operation applied to the value of the interface or in other wars,
time assertion is a process to extract the values of the interface.
Now you can see the syntax.
Here is the value of the expression of the interface and tee off her case is the type also known as
assault type.
The time assertion is used to check that the dynamic time of its operation will match the asserted type
or not.
If the tea is of concrete time, then the type assertion checks the given dynamic time of a is equal
to the tea here.
If the checking process is successfully, then the type assertion returns the dynamic value of a.
Or if the checking fails, then the operation will panics.
If the tea is of any interface time, then the time assertion checks the given dynamic time of a satisfying
tea.
Here, if the checking process successfully, then the dynamic value is not extracted.
Now let's go to Vet School program to illustrate how to use the time ASUSTOR.
First, define a function that accept the parameter as an empty interface.
For example, a funk display, a medieval as an interface.
Now, extracting the value of a and different type of a valuable for the example, in this case, visit
Eastern Time for a better value column equals a don't walk in and close Frances's and define.
This stream now display the value if p value, O'Connor says, value, the value will now go to main
function and involve the display function and plus the arguments as extreme to it.
First, define a string variable and initialize it that result.
He called and said, well, you go through your own language.
Now called the display function and send the result of a tweet display who said there isn't real reform
at the code, save the project and execute the program.
Now we can see the output value.
Colin, go programming language.
First, they define the function that accept a parameter as an empty interface and assign a string time
to it.
Then come the function and post a string value as argument to it and see the result.
In this example, if we change the value type of value variable from string to E., then the program
punch.
Now check this problem.
We change the value of result into an integer for the example.
123 save the project and execute the program again.
Now we can see the arrows.
So we want to overcome this problem.
First to the last quote.
Save the project and read it right?
First, define a function that accept an argument as an empty interface, a game for the example on
display set variable A. as A. Interface
go to the body.
OK, now extracting the value of a and different type of a value.
For the example, in this case, we set extreme time for a variable and assign it to two variables like
value and value comma.
OK column equals a don't open and close parenthesis and set a string as a tie.
Now display the value.
If if when you call in person.
The.
Status is percent v and calm here and sets venue and Oak Valley event here.
If the time of the day is equal to that string, then the venue contains the dynamic venue of the A
and okay will set to true.
And if the time of the air is not equal to a string, then auto is set to false and the venue contains
zero venue and the program does not punch.
Now go to main function and invoke the display function and post the arguments to eat.
First, define issuing variable and initialize each line.
Result equals go through your own language and call the display function and sent the result variable
to eat.
Display city resolved by data OK.
And second, define an integer variable and initialize it.
Go to the next line that results two equals.
Follow the example one hundred and twenty three and call display function and sent the result to variable
to eat, display and set the result variable to reformat the code.
Save the project and execute the program.
Now we can see the output value for string is go programming language and its titles, its true and
value for integer is zero and the phantoms is false.
In this case, for the extreme time, watching variable contains through value and for the entire time,
watching variable contains false value, and it does not given at all.
In order not to prolong the time of decision, we would finish it and we will continue the content in
the next session.
Goodbye.