So one thing we want to take care of before we can go live with this is to change the hard coded values
we have in our application to be read instead from command line flags.
So instead of running our application, as we do right now, so if we look at our run file, run S.H.,
instead of just running bookings, we're going to pass things like Debe name equals and then the database
name, which would be bookings and user, which would be, in my case, TC's and some other things as
well.
And we're going to do that in our main Dargo.
So for example, right here in the run function of our main Digo, I have app in production equals fault's
with the note to myself.
Changed this to true when in production.
Well I don't want to do that.
I don't want to recompile my application.
One version for local development and another version for production environments.
Instead, I want to read those values from the command line when I start the application and I'm going
to do that right here just after I register things for the session.
So in here I'll say red flags and obviously the first one I want is in production.
So I'll create a variable in production and I'll sign that the value of and this is a built in package
in the standard library Fleg.
And I'm going to read the type of argument I'm going to read from the command line Izabel and the value
I'm going to look for is production.
So that's what I'll be typing with.
A hyphen are like dash production equals true or false from the command line that will have a default
value of true.
So if you don't specify it, it will be set to true to be in production, which is always safe, or
you don't want to accidentally set something into development mode on a live server.
And then just the note that tells the user what the flag is for application is in production.
So that's the first value I want.
The second one is our cash.
Are we going to cash our templates or not?
So I'll just call this use cache and the command line flag will be cache.
The default will be true.
And the note to the user will be cache templates or use template cache.
OK, so we have two variables right now.
One for in production and one for true.
Now, the next thing I want of course, is to specify my database information because again, I don't
want a hard code that into the application.
So we need the DB name, the name of the database.
That will be a flag string and we'll call this one DB name and we'll have no default value for that.
We'll make that a required field and we'll just put the note database name and the database user DB
user.
Database user, the password Debe Pass.
Password, and we also want the port divi port, and I'll use that as a string, even though it's it's
a numeric value is string is fine for this case.
So I call this DB port.
I just to be consistent, I'll make everything lowercase for the flags.
So D.V. Port and I'm going to add one more here as well, which we haven't used yet, but in production,
quite often your connection to the database is using an SSL certificate.
So we'll specify DB, SSL and we'll make that have a default value of disable just so I don't have to
retype it or put a command line.
Feigin So database SSL settings
and for postgrads the possible values are disable, which will be the default prefer using SSL certificate
if it exists or require.
Don't start unless you have an SSL certificate on the database server.
Now other things I'm going to put in here, I'll make the database port default to five, four, three,
two and I'll make the database host, which I didn't specify yet.
So I better do that.
We need to have a DB host, DB host.
I'll just default that to localhost database post because sometimes you don't have the database on the
same machine as your application server.
Actually in production you rarely have the database on the same server as your your web app.
So that would be in a different host and you need to be able to specify that.
So I've got those all specified right now and they exist and they exist as pointers because that's how
things are run from the command line.
But before I can do anything with those at all, I have to call flag dot pers.
Now, these values will actually be passed and they'll be useful to our application.
So now that I have these specified, I can make a few changes.
So for example, instead of saying APTA introduction equals false, I can just say DOT in production
is equal to because it's a pointer pointer in production and I can do the same thing for app to use
cash.
I think it's called use cash, yes, and the variable in this case is use cash.
Now, do I have that anywhere down here?
Yes, so I need to get rid of this.
So those are set up now, what about our database stuff?
Well, that's all right here.
So instead of just passing a string in like this, let's create a new string, a new variable called
connection string,
and that will be assigned the value of the format as predictive.
And it will be the same thing we have here.
So let me just copy this, but with placeholders.
And I guess I got an extra quote in there that looks better and we're going to put in the very first
thing will be a string, which will be TV host.
So I have to use the star because it's a pointer DB host, and the next thing will be the port.
Do you report and then the DB name?
And then the TV user.
And then the password.
And then the one we just added, which is called SSL mode
along the line, but not much I can do about it.
All right, so that's our connection string now we'll just replace this with connection string.
OK, so if this works properly, we should be able to specify all of the necessary connection, strings
or command line parameters in our run DSH.
So let's put those in there.
So we have D.V. name, we have DBI user will say cache equals fault's.
There's no Comus will say production equals faults.
And we have the DB name, we have the user.
That should be enough.
Now there's one other thing I want to add here, and that is what if you try to start the application
but you haven't specified all of the necessary required parameters?
Well, we can do that right here after we pass our flag.
So DB Pass looks like I missed something here.
Do user to be poor TB's so password's.
So one, two, three, four, five.
One, two, three, four, five.
Oh should be do doing pass by.
Idy helpfully told me that I missed a variable.
So that's those.
Those should all be correct now.
But after we pass the flag right here, let's make sure that they've specified all of the necessary
required flags.
So if you need to have DB name, so DB name is equal to nothing or.
And what are the required flags.
Do we have here db user DB pass.
We can leave empty because we don't have a password in our production environment or development environment.
I think the only other one we need is our DB user.
If that's equal to nothing, then format that print line missing, required flags and then will just
exit.
With a code of one that should stop the application.
So if I try running this right now, first of all, let's just get rid of these parameters that we specified
and we'll see what happens.
So let me cut those.
So they're on the clipboard and I won't lose them.
And let's try running this
in the right direction.
I am so run.
And it should say missing required flags, and it does.
Now let's go paste them back in
and try writing it again and there it is running.
We're all connected in the database, so let's make sure it works.
And go to localhost 80, 80, and it works.
Can I log in?
And I can and I should see things on the dashboard, and I do perfect.
OK, so now we can just by changing our run script, we can have our product or our code run in properly
in production, and we can have our code run properly in our development environment.
And that makes a lot more sense than hard coding things into our source code.