This post discusses tips and best practices for writing HTTP services in Go, including structuring servers and handlers, optimizing for performance, handling common work, and properly testing services.

21m read timeFrom grafana.com
Post cover image
Table of contents
Who is this post for?The NewServer constructorMap the entire API surface in routes.gofunc main() only calls run()Maker funcs return the handlerHandle decoding/encoding in one placeValidating dataThe adapter pattern for middlewareSometimes I return the middlewareUse inline request/response types for additional storytelling in testssync.Once to defer setupDesigning for testabilityPutting this all into practice
2 Comments

Sort: