We don't want to duplicate the code to create the sqlite connection in every route. We'll use web middleware to inject the connection.
- [Narrator] Hi, and welcome back.…In our last videos,…we built a search UI for our library app,…allowing users to select and save books…to his or her collection.…We've been leaning heavily on the standard library…to build our web application so far,…however it's worth noting that there are many…third party tools available to make our lives easier.…In this video, we'll take a look…at the world of web middleware…and the benefits a good middleware library can provide.…We'll start by installing…a web middleware handler called Negroni.…Then, we'll use Negroni in place of our default web server.…
Finally, we'll create our own custom middleware…to handle verifying the database connection…before each route.…Web middleware is code that sits between where we'll request…and our application code.…Middleware can be used before, after, or around rounds,…but most common used case is to use these calls…to perform actions before your route handler's called.…Negroni is advertised as an idomatic approach…to web middleware.…It's small, reliable, and easy to use,…
Go is on the rise. This open-source programming language (created by Google!) comes with a strong and accessible standard library, and provides a growing ecosystem of tools, libraries, and frameworks that can help you build web applications fast. Go for Web Development gets you started with the language, opening with the classic "Hello world" exercise and culminating in a web application with a strongly designed database back end, useful middleware, UI with an intelligent search function, multi-user authentication, and more.
First, learn how to build a web server with Go's extensive standard library. Explore the concepts behind a single-page web application and learn how to create a dynamic user interface, manipulate a database, and use powerful encryption algorithms to implement an authentication system. Next, you'll incorporate more functionality by calling out to external libraries from the database. Finally, it all comes together into an optimized package you can deploy into the wild with Heroku.
- Creating a route in Go
- Using templates
- Building database connections
- Collecting data
- Using web middleware
- Using the Ace template engine
- Integrating HTTP routers like gorilla/mux
- Authenticating users
- Optimizing a Go codebase