So, as promised, this time around, I want to not use the pat router, instead, I want to use the
key router and let's have a look at that.
So over on my Web browser, I go here to GitHub, Dotcom, Shūgo, Dash, Kiguchi.
And when I look at the actual description of this, it seems pretty good.
It's a good writer.
It's it's it's lightweight.
It's fast.
It's absolutely compatible with the standard library net HTP.
It seems to be exactly.
Are very useful.
And one of the other nice things about this is if you scroll down you'll see it has some built in middleware,
which we haven't talked about yet, but we're going to in the upcoming lectures, middleware allows
us to process requests as they come in and make decisions about what to do with them.
So, for example, I might have some pages on my site that I only want logged in users to see.
And middleware is a great place to determine whether or not a user has the necessary rights to see that
page.
So it has a whole bunch of built in middleware.
And you can see there there's all kinds of them listed right here and you can read those at your leisure
will be using some of them, some of them in the next few minutes.
All right.
So how do I install this?
Well, this is the same process we used to install, Pat.
So let's find the install part.
Should be go get somewhere in this page.
Go get there it is install.
Go get.
So I'm going to copy that, go back to my ID, open a terminal window, stop my application because
I had it running and I'll clear the screen and simply paste that command in and it goes and gets it.
And again, if we look at our Gadot mod file, which is right here, it's now an important GOCE.
It still has Pat, and we're still using Pat, but we're not going to be in just a moment.
So how do I use this?
Let me go back to my roots folder and let me just delete everything in the middle here.
I'll just comment to that.
All right, so now it says, we're not using Pat, you're not using handlers and we will be in a minute,
so don't ignore those errors if you see them, instead of creating a new mux that is a type of pat,
let me create a mux that is of type Chey dot newsreader.
All right.
So it got rid of Pat up here because we're not using it anymore.
It's still in our go mode file, which I can show you right here.
We don't want that.
Now, you could manually delete this, but we're not going to will simply do a much cleaner method,
will go down to our terminal window and say go mode tidy, tidy up my mod file, and when I do, it
actually gets rid of unused packages.
OK, so you're going to be doing that periodically and later on I'll show you how to update your dependencies
so you may draw in a third party package that's updated and has some new features and you want to use
the new version, but we'll get to that later on.
Right now, we're just putting a restaurant.
So I've created my new key router and I have a Mac and I'm returning the mux.
Now, I want to have these pads matched in our router the same as we did before.
So it's a very similar approach.
Mux dot get the pattern is slash for home and I'm just going to go handler's repo, not home.
Now, that seems like it works pretty well.
OK, let's copy that one and do the one for boat route home.
A report a boat seems to have worked.
Let's compile it and see what happens.
Go run command web main first sorry, StarTalk, go it compiled seems to be running.
Let's go to our Web browser and open a new window and go to localhost.
Eighty, eighty.
There's the homepage perfect, and let's have a look at our about page to make sure that works about
very good, that works extremely well.
Now, why did I go to all the trouble of changing Rotor's?
Well, the first to start with it was actually just to show you that it's not that difficult if you
keep things separated from one another and keep things really clean.
You can swap out an entire component of your package in just a couple of minutes, which is exactly
what we just did.
But there are other reasons I want to use this particular router as well.
So I'm going to get rid of this commented code and I'm going to install some middleware.
Now, as I said, middleware actually allows you to process a request as it comes into your Web application
and perform some action on it.
Well, let's go back to our Web browser and look at the list of middleware, which is way down here
somewhere.
There it is.
Let's look at some of these.
Some of these actually seem pretty good.
Here's one.
Recover gracefully, absorbs panic's and prints the stack trace.
So sometimes hopefully not very often if you've if you've coated carefully, but sometimes your application
will panic and a panic says, oh, no, the world is coming to an end, I am going to die, and your
application just dies.
What you would want to do instead is say, oh, no, something really bad happened.
Here's some useful information about what went wrong and now I'm going to recover from that panic.
So maybe I want to use this Rickover Middleware.
Well, how do I do that?
Well, it's actually pretty easy.
I can just say mux don't use middleware, which is one of the things built into CZI and I want to find
the Rickover.
So Rickover, that's it.
And I don't want those parentheses.
That's it.
So when I put that middleware in place because I've used it before these roots, it's actually available
to us now.
Are there any other ones that I want to put in there?
Well, at the moment, let's have a look and just make sure.
Is there anything else I want to use in those middleware?
So let's find them again, allow content type basic auth.
Not here, but basically if I want to use a more more secure version of authentication compress that'll
be handled by my Web server.
Don't care about that monitoring endpoint logger.
What's Logger do logs the start and end of each request with the elapsed processing time.
Now that'll be available to me in other ways.
Well, for right now I'm not too worried about the rest of this.
This seems to me like it might be OK.
So we're going to make some more middleware and we'll do that in the next lecture.
But for right now, this is pretty good.
We have this running.
So let's stop right now.
In the next lecture, we'll look at actually writing our own middleware and using that in here, because
sometimes what you need just doesn't come out of the box with your router.
Actually, quite often it doesn't come out of the box with your router.
So we'll write some basic middleware and add those in the next lecture.