Networking and services
A service is a handler, a client, and the limits around both. These lessons build an HTTP server and its routes, middleware, a client with a timeout, a JSON API, HTML from templates and a shutdown that waits for the requests in flight. They then add the storage side: database/sql, transactions, migrations, CORS and the timeouts that protect the process.
093
An HTTP server with net/http
http.ListenAndServe, a handler function, the request and the response, and a server that runs
Open
094
Handlers, ServeMux and patterns
ServeMux, method and path patterns, r.PathValue and a 404 written by hand
Open
095
Middleware
a handler that wraps a handler, logging, a header and the chain in order
Open
096
An HTTP client
http.Get, a timeout, a custom Transport, the response body closed and an error checked
Open
097
A JSON API by hand
decode a request body, encode a response, the status codes and a handler per route
Open
098
HTML from templates
html/template in a handler, a layout, escaping and a page that renders data
Open
099
Graceful shutdown
signal.NotifyContext, Server.Shutdown, a context deadline and an in-flight request that finishes
Open
100
database/sql
sql.Open, a driver named in words, Query and QueryRow, Scan and the pool settings
Open
101
Transactions and prepared statements
Begin, Commit and Rollback, a prepared statement and a transaction that fails halfway
Open
102
Schema migrations
a version table, an up step applied once and a migration that runs at start-up
Open
103
CORS and a dev proxy
the CORS headers, a preflight request, a proxy in development and the same origin in production
Open
104
Timeouts, body limits and slow clients
server timeouts, http.MaxBytesReader, a slow client and the limit that protects the process
Open