Unit content
Web applications in Go
Go's standard library provides the main pieces needed to build a server-rendered web application without a web framework.
Handlers and routing
net/http represents server behaviour through http.Handler:
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// interpret request and write response
}
An http.ServeMux maps HTTP methods and paths to handlers. Handlers should translate HTTP input into application operations and translate results back into HTTP responses.
Requests and responses
The request exposes its method, URL, headers, body and form data. The response writer controls headers, status and response bytes.
Validation and authorization should happen before protected state is changed.
Middleware
Middleware wraps a handler to apply behaviour shared by many routes, such as authentication, authorization, request logging or security checks:
request → middleware → handler → response
Request contexts carry request-scoped values, cancellation and deadlines across calls without turning them into global state.
HTML templates
html/template renders server-side HTML while applying context-aware escaping to inserted values. Applications commonly parse templates once and execute them with view data for each request.
Complete pages and smaller HTML fragments use the same underlying model.
PostgreSQL through database/sql
Go's database/sql package exposes pooled database connections through *sql.DB. Application code uses parameterized queries for reads and writes and *sql.Tx when several operations must commit or roll back together.
The SQL and database invariants remain explicit; database/sql is a database interface, not an object-relational mapper.
Concurrent requests
An HTTP server may execute handlers for different requests concurrently. Request-local values are naturally separate, but mutable state shared between handlers must be designed for concurrent access.
Go web applications combine ordinary Go packages with HTTP, templates and relational persistence rather than replacing those concepts with framework-specific abstractions.