Hello and welcome to the Golang programming language course.
In the previous session, we could define channels for chat application, and now it's time to design
and implement methods for the channels created.
First, you want to create a method for adding a client, so define the middle name like register clients.
Because these methods are related to the config restaurant.
We define a receiver for them, so we'll be right fine set the receiver config pointer off config and
set a name, for example.
Register.
Client.
These metal accept a connection as input parameter playing by the time pulling trough.
We have such a connection.
Now he wants to implement the body of method, this method is supposed to end the current connection
as a client to the client's map.
So we write config
that clients
now that content connection IP as the key for the map for access, the IP of the client recording agreement
at this function.
So the right client got removed.
Address dots is.
And initialize it by the client equals client.
For display, the list of claims we can use from pain and function.
FP
clients.
Country that claims now we can see the IP of each client.
We could define the method for add a new client and class map.
Now we want to create a method for removing the client, so define the method name like remove clients.
Fine.
Set a precedent, for example, config.
By the time Poitras kind of set a name, for example, Reno.
Client,
despite the fact that the connection is input parameter, client, web socket, the connection.
Now he wants to implement the body of method, this method is supposed to remove the connection of the
client from the client's map for this purpose, declining delete function, the delete built in function
delete as the element with the specified key from the map.
This function acts that two parameters first the map collection and second, the key of the element
to be removed from the map.
So calling delete function.
Said clients map as arguments feek dot clients and sit IP of client as key argument clients start remote.
Address Dot estranged.
Now we can see the list of clients after a dirty move by the Colleen and Function FP
clients.
And calling conflict that class now, we could define the method for removing the client from our client's
map.
Now it's time to design the method whose job is to transfer data from the server to the class.
So define the method name like Message Data's
fine set a receiver, for example Palm Beach from comfiest strong
message dataset.
This method accept an object from message extract as input parameter, for example, research by the
typed message S3.
The job of this method is to call the clients in the client's mapped election and send it, these are
a message to the whole clients.
So we use the range loop to iterate the clients.
So we write full on the word score.
Comma defined a variable like client column equals range.
We want to iterate lists of clients so calling class map from configure struct config.
But clients,
now we want to send the message to each client to do these videos from Jason Cadec.
Jason is a codec to send or receive JSON data in a frame from an VIPs get connection.
So from which to get packages, putting JSON and invoking send method.
This function returns and or object.
So first, define and error variable.
Error column equals this wicked dot JCR
dot send function.
This method acts the two parameters.
First, the connection.
So we set client.
And second is an object.
In this case, our argument is a object from messages struct.
So we send message.
Now, check status or
if it or not, equals need Lott, the fatal error don't now we could define a method for send data from
Syria to clients in order not to prolong the time of decision.
We will finish it and we will continue the content in the next session.
Goodbye.