Hello and welcome to the Guoliang programming language course in the previous session, we were able
to make configuration for the rest later, and in this session, it's time to design the main method
and create the connection to the database and then run the server to be ready to respond to the created
endpoints.
So go to Project Folder and create a file name like main school name.
The School First set package name defined main function.
Before we can access details in the MySQL database, we need to create a connection to the database.
Previously, we designed a method called Connect in the Tools package, which contains a method called
open from this Google package, which by taking two values of driver name and data source name, creates
a connection to the MySQL database.
And we also previews the saved driver name and data source name information inside adjacent file in
the configuration package.
Now it's time to use the information our JASON find to connect to DB for using the JSON, find the calling
open function from OS package that opens the main file for reading it.
Successful methods are returned fire and can be used for reading open function, exit file pipe as input
parameter and returns to value first and object from five and the other an object from error.
So we defined two variables named fine, and it will find common error calling equals and calling open
function from this package.
Now set Jason five pattern input argument as a string type data base can be Grecian and config dot JSON
fine.
Now check error status if error not equals need large fatal error that.
Yeah.
We use Ether for closing the created file object, Ether.
Fine.
But close.
Now, create this rock on top of the main method that contains variables equivalent to the keys in the
Jason fine that are used to map those keys to their data types and.
So define a stroke like name configuration.
Go top of the main function time.
Can figuration extract?
Driver name derived very name type is strange using Jason Pack.
Ji Sung Colin and Sydney driver nee.
To either
me and again for data, source name, date, source name, type is a string and using Jason Tak, Jason
Cullen and sit name data.
Source name,
date, source name.
Now, create an object from configuration extract, so define a variable like cars go after ether columns
column equals new
configuration as struct.
Now, using the new decoder function of the JSON package, we sent the Jason fine to eat as a parameter
after opening it and through the decode method in the next JSON encoded value from its input and assaulted
in the value pointer to object created from the configuration S2.
So we write Jason, the new decoder said finance argument.
And calling Typekit function and sitcoms as argument for it.
This allowed us to assert the values inside the Jason fight in the very building the configuration is.
Now it's time to call the initialize method from the DB tools package to connect to the database.
DB tools, dot db initialize and set driver name from the conflict.
Convert driver name and set data source name of the data source name.
Each of the current methods uses a method called Connect to communicate with the database, which requires
two parameters that we were able to inject into the DB tools package.
OK, necessary conditions for communication with minuscule database are provided.
Now it's time to run our server by calling list a start function from the rest layer, so we write risk
layer at rest start function.
And sip localhost IPA argument for it.
A hundred and twenty seven dots, zero dots, zero got one colour and said 880 port.
OK, now the server is ready to listen to client requests in order not to prolong the time of decision.
We will finish it and we will continue the content in the next session.
Goodbye.