
Redirects in Go and the Right Status Code to Use for Each
Pick between 301, 302, 303, 307 and 308 in Go with http.Redirect, see which keep the method and body, and avoid open redirects from a query value.
Tag
5 articles

Pick between 301, 302, 303, 307 and 308 in Go with http.Redirect, see which keep the method and body, and avoid open redirects from a query value.

Decode request JSON strictly in Go: DisallowUnknownFields, a single-value check, body limits and a map from decoder errors to 400, 413 and 422 answers.

Route api, admin and www hosts to different handlers with one http.ServeMux by putting the host in the pattern, and learn how it treats ports and case.

Replace the plain text 404 and 405 responses of http.ServeMux with your own pages or JSON, using a catch-all route and a small response wrapper.

Publish counters and gauges from a Go service with the standard library expvar package, mount its handler safely and see when Prometheus is the better choice.