Web Development with Go

Web Development with Go

English | MP4 | AVC 1920×1080 | AAC 44KHz 2ch | 248 Lessons (35h 33m) | 12.50 GB

Web Development with Go

Learn to build real, production-grade web applications from scratch.

No trivial TODO apps that barely touch the complexity of a real app.

No frameworks that hide all the details.

In this course we build and deploy a photo sharing application complete with users, authentication, image uploads, a database, and more. We even deploy to a production server and set up automatic HTTPS.

Web Applications are Complex Systems
No matter how many tutorials I read, I always felt like there was something left out. Some part of the bigger picture that wasn’t explained, leaving me unsure of how to proceed. Or the tutorial was oversimplified to the point that it felt useless in the grand scheme of things.

After building several TODO apps I nearly gave up. My progress was painfully slow, and every time I figure out one major problem I would be left with two new questions that weren’t addressed by the oversimplified tutorials.

In the end, I was lucky. I happened to have a history building web applications using other programming languages, and with that knowledge I was able to piece things together. It wasn’t quick or easy, but it all slowly started to make sense.

What if you didn’t have to struggle through hundreds of tutorials?
What if you didn’t have to go through the painful process I did to learn how to build web services in Go? What if you could skip reading hundreds of tutorials all teaching roughly the same thing just to get one new tidbit of information out of it? You would finally be ready to build that application you have been considering, or apply for that job you had your eye on.

Web Development with Go will help you cut through all the complexity and finally become the developer you know you should be.

Table of Contents

1 A Basic Web Application
2 Troubleshooting and Slack
3 Packages and Imports
4 Editors and Automatic Imports
5 The “Hello, world” Part of our Code
6 Web Requests
7 HTTP Methods
8 Our Handler Function
9 Registering our Handler Function and Starting the Web Server
10 Go Modules
11 Dynamic Reloading
12 Setting Header Values
13 Creating a Contact Page
14 Examining the http.Request Type
15 Custom Routing
16 URL Path vs RawPath
17 Not Found Page
18 The http.Handler Type
19 The http.HandlerFunc Type
20 Exploring Handler Conversions
21 FAQ Exercise
22 Router Requirements
23 Using Git
24 Installing Chi
25 Using Chi
26 Chi Exercises
27 What are Templates?
28 Why Do We Use Server Side Rendering?
29 Creating Our First Template
30 Cross Site Scripting (XSS)
31 Alternative Template Libraries
32 Contextual Encoding
33 Home Page via Template
34 Contact Page via Template
35 FAQ Page via Template
36 Template Exercises
37 Code Organization
38 MVC Overview
39 Walking Through a Web Request with MVC
40 MVC Exercises
41 Creating the Views Package
42 fmt.Errorf
43 Validating Templates at Startup
44 Must Functions
45 Exercises
46 Embedding Template Files
47 Variadic Parameters
48 Named Templates
49 Dynamic FAQ Page
50 Reusable Layouts
51 Tailwind CSS
52 Utility-first CSS
53 Adding a Navigation Bar
54 Exercises
55 Creating the Signup Page
56 Styling the Signup Page
57 Intro to REST
58 Users Controller
59 Decouple with Interfaces
60 Parsing the Signup Form
61 URL Query Parameters
62 Exercises
63 Intro to Databases
64 Installing Postgres
65 Connecting to Postgres
66 Update: Docker Container Names
67 Creating SQL Tables
68 Postgres Data Types
69 Postgres Constraints
70 Creating a Users Table
71 Inserting Records
72 Querying Records
73 Filtering Queries
74 Updating Records
75 Deleting Records
76 Additional SQL Resources
77 Connecting to Postgres with Go
78 Imports with Side Effects
79 Postgres Config Type
80 Executing SQL with Go
81 Inserting Records with Go
82 SQL Injection
83 Acquire a new Record’s ID
84 Querying a Single Record
85 Creating Sample Orders
86 Querying Multiple Records
87 ORMs vs SQL
88 Exercises
89 Syncing the Book and Screencasts Source Code
90 Steps for Securing Passwords
91 Third Party Authentication Options
92 What is a Hash Function?
93 Store Password Hashes, Not Encrypted or Plaintext Values
94 Salt Passwords
95 Learning bcrypt with a CLI
96 Hashing Passwords with bcrypt
97 Comparing a Password with a bcrypt Hash
98 Defining the User Model
99 Creating the UserService
100 Create User Method
101 Postgres Config for the Models Package
102 UserService in the Users Controller
103 Create Users on Signup
104 Sign In View
105 Authenticate Users
106 Process Sign In Attempts
107 Stateless Servers
108 Creating Cookies
109 Viewing Cookies with Chrome
110 Viewing Cookies with Go
111 Securing Cookies from XSS
112 Cookie Theft
113 CSRF Attacks
114 CSRF Middleware
115 Providing CSRF to Templates via Data
116 Custom Template Functions
117 Adding the HTTP Request to Execute
118 Request Specific CSRF Template Function
119 Template Function Errors
120 Securing Cookies from Tampering
121 Random Strings with crypto/rand
122 Exploring math/rand
123 Wrapping the crypto/rand Package
124 Why Do We Use 32 Bytes for Session Tokens?
125 Defining the Sessions Table
126 Stubbing the SessionService
127 Sessions in the Users Controller
128 Cookie Helper Functions
129 Create Session Tokens
130 Refactor the rand Package
131 Hash Session Tokens
132 Insert Sessions into the Database
133 Updating Existing Sessions
134 Querying Users via Session Token
135 Deleting Sessions
136 Sign Out Handler
137 Sign Out Link
138 SQL Relationships
139 Foreign Keys
140 On Delete Cascade
141 Inner Join
142 Left, Right, and Full Outer Join
143 Using Join in the SessionService
144 SQL Indexes
145 Creating PostgreSQL Indexes
146 On Conflict
147 What Are Schema Migrations?
148 How Schema Migration Tools Work
149 Installing pressly/goose
150 Converting to Schema Migrations
151 Schema Versioning Problem
152 Running Goose with Go
153 Embedding Migrations
154 Go Migration Files
155 Removing Old SQL Files
156 Using Context to Store Values
157 Improved Context Keys
158 Context Values with Types
159 Storing Users as Context Values
160 Reading Request Context Values
161 Set the User via Middleware
162 Requiring a User via Middleware
163 Accessing the Current User in Templates
164 Request-Scoped Values
165 Password Reset Overview
166 SMTP Services
167 Building Emails with SMTP
168 Sending Emails with SMTP
169 Building an Email Service
170 EmailService.Send
171 Forgot Password Email
172 ENV Variables
173 Password Reset DB Migration
174 Password Reset Service Stubs
175 Forgot Password HTTP Handler
176 Asynchronous Emails
177 Forgot Password HTML Template
178 Initializing Services with ENV Vars
179 Check Your Email HTML Template
180 Reset Password HTTP Handlers
181 Reset Password HTML Template
182 Update Password Function
183 PasswordReset Creation
184 Implementing Consume
185 Inspecting Errors
186 Inspecting Wrapped Errors
187 Designing the Alert Banner
188 Dynamic Alerts
189 Removing Alerts with JavaScript
190 Detecting Existing Emails
191 Accepting Errors in Templates
192 Public vs Internal Errors
193 Creating Public Errors
194 Using Public Errors
195 Galleries Overview
196 Gallery Model and Migration
197 Creating Gallery Records
198 Querying for Galleries by ID
199 Querying Galleries by UserID
200 Updating Gallery Records
201 Deleting Gallery Records
202 New Gallery Handler
203 views.Template Name Bug
204 New Gallery Template
205 Gallery Routing and CSRF Bug Fixes
206 Create Gallery Handler
207 Edit Gallery Handler
208 Edit Gallery Template`
209 Update Gallery Handler
210 Gallery Index Handler
211 Discovering and Fixing a Gallery Index Bug
212 Gallery Index Template Continued
213 Show Gallery Handler
214 Show Gallery Template and a Tailwind Update
215 Extracting Common Gallery Code
216 Extra Gallery Checks with Functional Options
217 Delete Gallery Handler
218 Images Overview
219 Setting Up Test Images
220 Adding the ImagesDir to the GalleryService
221 Globbing Image Files
222 Adding Filename and GalleryID to the Image Type
223 Adding Images to the Show Gallery Page
224 Show Image Handler
225 Querying for a Single Image
226 URL Path Escaping Image Filenames
227 Adding Images to the Edit Gallery Page
228 Delete Image Form
229 Delete Image Service Func
230 Delete Image Handler
231 Checking for Filename Vulnerabilities
232 Upload Image Form
233 Image Upload Handler
234 Creating Images in the GalleryService
235 Detecting Content Type
236 Rendering Content Type Errors
237 Deleting Images on Gallery Deletion
238 Redirect to Galleries After Auth
239 Loading All Config via ENV
240 Docker Compose Overrides
241 Building Tailwind Locally
242 Tailwind Via Docker
243 Serving Static Assets
244 Making main Easier to Test
245 Running our Go Server via Docker
246 Multi-Stage Docker Builds
247 Tailwind Production Build
248 Caddy Server via Docker

Homepage