Since Go was first open sourced in 2009, it's rapidly grown in popularity, and is especially suited to creating web applications due to its focus on simplicity and rich standard library. In this course, Creating Web Applications with Go, you'll learn how to create web applications in Go with minimal third party library support. First, your journey will begin with an introduction to how to create simple HTTP request handlers, and an exploration of Go's powerful templating capabilities. Next, you'll discover how to create a controller layer with dynamic routing and middleware, and how to interact with a database. Finally, you'll learn how to test your applications to ensure they perform as expected. When you're finished with this course, you'll be fully equipped to create your own cutting edge web applications with the Go language.
Michael Van Sickle is an application architect in Akron, Ohio.
He is a mechanical engineer by training and a software engineer by choice.
He is passionate about learning new programming languages and user
Course Overview Hi everyone, my name is Michael Van Sickle and welcome to my course, Creating Web Applications with Go. Since Go is first open sourced in 2009, it is rapidly growing in popularity and is especially suited to creating web applications due to its focus on simplicity and its rich standard library. In this course, we're going to learn how to use Go to create a full featured web application following the model, view controller design pattern. Some of the major topics that we will cover include, how to use Go's templating framework, how to create parametric route handlers for our controllers, how to communicate securely and efficiently with https and http2 and finally, how to test in profile web applications. By the end of this course, you'll know how to create applications that are fast and robust. Before beginning the course, you should be familiar with the Go language as well as foundational web technologies such as, HTML and CSS. From here, you should feel comfortable learning about some of the existing web frameworks for Go, with courses on Beego, Revel and Gin. I hope you will join me on this journey to learn how to make web applications with the Creating Web Applications with Go course at Pluralsight.
Introduction Hello, and welcome to this course where we're going to be learning how to create web applications with the Go language. Now in this foundational module, we're going to be introducing the basic concepts that we're going to be building on throughout this course. So the first question we're going to answer is why is Go a good choice for web application development at all? Then we'll move into our discussion of the prerequisites that you're going to need to be familiar with in order to get the most out of this course. After that, we're going to review the development environment that I'll be using throughout this course, and use that to build our first web application. Next, I'm going to introduce the demo application to you. Now in this module, we're going to see that the demo application is just a collection of static HTML pages. Throughout this course, what we're going to be doing is applying what we've learned to the demo application and watching it evolve from that basic collection of static HTML pages into a full data-driven web application. In order to guide that evolution, we're actually going to be applying the MVC design pattern or model view controller pattern that is the foundation for many web application frameworks, and so in order to make sure that we're all on the same page I'm going to do a quick review of the MVC design pattern so that you see what each one of the layers is for and as we get to that layer, you'll have a heads up about where we're going with it. And then finally I want to wrap up with a course outline. So there's quite a bit of material that we have to cover in this course, and I want to give you an introduction to what the major topics that we're going to cover are, and when you can expect to see those. Okay, so let's dive right in and learn why Go is a good choice for building your next web application.
Handling Basic Requests Hello and welcome back. In the last module, we talked about why Go is a good candidate to consider when you're creating your next web application. We also got our first taste of what it looks like to build a web application using the Go language. In this module, we're going to dig deeper into the basic APIs that are going to form the core of every web application that you're going to build using the Go language. Now we're going to start that conversation by talking about how Go handles connections. Go contains within its standard library some objects that are going to help us receive HTTP requests and handle multiple requests at one time and we'll talk about how it does that in this first section. Then we'll move on to talk about the basic request handlers and in this section we're going to talk about the functions that are available to us to map a request coming in at a specific URL over to a function that will allow us to handle that request. And then we're going to finish up our discussion by talking about some of the built in handlers that come with the Go language. So in Go standard library there are some handlers that are pre packaged for us to handle some common use cases. Okay so let's go ahead and get started by learning how to handle web connections with Go.
Templating Basics Hello, and welcome back. In the last module, we learned about the basic APIs that are going to form the core of every web application that you're going to build in Go. In this module, we're going to start learning about the template package in Go that's going to allow us to build the view layer of our web application that's following the model-view-controller design pattern. Now at first glance, templates might seem like a fairly simple concept, but there's actually quite a bit of functionality that Go's going to provide us in its template package. So we're going to go through that step-by-step. The first thing that we're going to talk about is the purpose of templates themselves, so we're going to talk about what templates are, and how we can use them to build the views in our web application. Then we're going to introduce the basic functions, so we're going to get a very simple template up and running, and show you how to use it to generate some output. Then we'll learn how to load templates from the file system and get them into your application. We'll learn about subtemplates and template composition. And finally, we'll introduce data into our templates to make our templates truly dynamic. Okay, so let's get started by learning why we have templates in the first place.
Creating Smart Templates Hello, and welcome back. In the last module, we introduced Go's templating package, and we talked about how we can use templates to both organize a view layer using sub-templates and template composition, as well as how to dynamically generate a content by making our templates data driven. In this module, we're going to dive deeper into the templating package and learn how to make our templates even more powerful and flexible. This conversation is going to break down into five parts. The first thing that I want to introduce is the concept of the pipeline. Now we've actually been working with pipelines for a little while now, but I want to formally introduce them to you so that you know what they are and how to work with them. Then we'll talk about the built-in functions that are available in our templates and how to use them. We'll introduce custom functions and how you can register your own functions to be available in your templates, and then we'll talk about how to add logical tests so that we can add branches into our templates so that we can decide whether or not to render a certain piece of content based on the data that's available, and then we'll talk about looping and how we could use that in order to automatically generate repetitive bits of code. Okay, so let's started by having a formal introduction to pipelines.
Routing Requests Hello and welcome back. In the last few modules we took a look at Go's templating packages and saw how they enable us to build a powerful and flexible view layer in our application. In the next few modules we're going to change our focus and look at how to build a controller layer. These discussions are going to be a bit different from the last ones however. The key to creating a great view layer in Go is by learning about the templating packages. We don't have any packages to help us create controllers however. As a result we're going to focus on the architecture of our application itself to make sure that the controller layer is flexible and maintainable. We're going to start our discussion by learning about what the role of a controller is. Now we touched on this a little bit in the first module, but I want to revisit it, especially in light of the demo application that we've been building and talk about some of the problems that a well-built controller layer are going to help us solve. We'll then talk about how to use our controller layer to handle static routing and then we'll move on to a concept called parametric routing where we're going to take information from the request in order to shape the result that gets generated by the view layer. And then finally we're going to talk about third party routers. Now throughout this course we're only going to be using the standard library with one exception and that is a database driver that we'll talk about in a future module. And I think that you'll find that handling routing in your web application is pretty straightforward just using the tools that Go provides us out of the box. However there are some very nice third party routers out there that I want to introduce you to because you can just drop those into your application and get a lot of functionality very, very quickly. Okay, so let's get started by reviewing what the role of a controller is in our web application.
Working with HTTP Requests In the last module we learned how to route requests to handlers in our applications. Well, now that we have them there, it's time to learn what we can do with them and that's what we'll be covering in this module. We'll start this discussion by talking about query parameters. Now, this is going to be one of the primary ways that you 're going to send data from the URL into your request handlers and so, we'll talk about those first. We'll then move on to talk about form data and how we can retrieve data that's sent to our request handler via an HTTP form post. We'll then talk about how to work with our web pages asynchronously by talking about how to send and receive JSON and then we'll talk about some built-in responses that come in the standard library that support many common response use cases. Okay, so let's get started by learning how to work with query parameters in our request handlers.
Creating Middleware In the last couple of modules, we've learned how to route requests to handlers in our application as well as what we can do with those requests once we get them there. In this module, we're going to talk about another type of feature that can be present in the controller layer, middleware. Now we'll start that conversation out by talking about what middleware is and what we can do with it in our web applications. Then we'll go through the process of creating our own custom middleware. And then I want to take a second to talk about something called a request context. Now middleware isn't the only thing that's going to take advantage of a request context, but I do want to talk about that here so we can wrap up our discussion of the controller layer. Okay, so let's go ahead and get started by learning what middleware is and what we can do with it.
Interacting with a Database Hello and welcome back. In the last module we finished up our discussion of how to create a controller layer for a Go web application based on the model view controller design pattern. In this module, we're going to talk about the model layer. Well, we won't actually talk about the model layer itself since this layer will be unique to every application, rather we'll talk about how to get the model layer to interact with the persistence layer. More specifically, we'll be learning how to wire an application up to a postgres database. We're going to take this conversation in several steps. We're going to start at the very beginning by learning how to connect our application to a database itself. Once we have that connection established, we'll learn how to run some queries to pull some data from the database and then we're going to turn things around and learn how to update the database from our application and we're going to wrap the module up by talking about some other activities that you can do with a database, for example, managing transactions. Okay, so let's get started by learning how to connect our web application to a database.
Beyond HTTP/1.1 Throughout most of this course, we've been focused on the components that make up a web application itself. In this module, I'd like to take a step back and talk about another critical piece of a web application, the protocol that is used to transfer data between clients and servers. So far, our application has transferred all of its data using the HTTP protocol, but I'd like to talk about some other options that we have available and the advantages that they bring. So we'll start talking about HTTPS and how we can secure the communication between our clients and servers by using this protocol and I'd like to show you how to add that into your Go web application. And then I'd like to talk about HTTP/2. Now at the time that we're recording this course, this is the latest version of the HTTP protocol, and it comes with several features that can significantly improve the efficiency of how data is actually transferred between your clients and servers. And then to wrap this module up, I'd like to focus on one specific aspect of HTTP/2 that is now available as of Go 1. 8, and that is how we can do something called a server push. So let's get started by talking about HTTPS and how we can modify our web applications to take advantage of it.
Testing Web Applications In the last module, we changed our focus a bit. Instead of talking about the components and features of a web application itself, we started to talk about some of the supporting technologies that a web application uses, specifically how to get our application to use HTTPS and how to take advantage of the HTTP/2 protocol. In this module, I want to focus on some other tools that support modern web application, testing, and profiling. We'll start our discussion by talking about unit tests and how different layers of our application are going to face unique challenges to creating isolated units. So we'll start by talking about the model layer and some of the unique challenges that it faces, and we'll see how to deal with those, and then we'll move over to the controller layer and see how we can test that. Now, we're not going to focus on the view layer, because the view layer can be exercised with very traditional tasks. Basically all that we would do there is create some unit tests to ensure that templates are executed properly. And actually, testing the view layer is often best done via integration tests or human tests, because it's easier to see if the entire application is working together. After we finish our discussion of unit tests, we're going to talk a little bit about performance profiling and how we can instrument our web application to see how it's doing in terms of memory consumption as well as how much load it's putting on the processor. Okay, so let's get started by talking about how to create some unit tests specifically focusing on the model layer.