Write Once, Use Many: A Handy Package to Call Internal HTTP APIs
summary
A reusable Go package called bitly service encapsulates all internal HTTP calls so one implementation handles service discovery, host selection via a hostpool, consistent headers and JSON unmarshalling, logging, tracing, timeouts, and error handling. Initialization requires calling must_add_named_api which panics on misconfiguration, and testing uses a hook mechanism to mock responses. The code reduces repeated client.Request/Client.Do boilerplate to thin wrappers (get/post/put/patch/delete) and is used 336 times across the codebase.
AI-written summary · about
chapters (12)
- 0:00Intro
- 1:17Bitly System Architecture
- 2:38Standard lib HTTP calls
- 6:33Solution - Encapsulate it all into a reusable package
- 8:02Under the covers - bitlyservice does all the work
- 8:58bitlyservice. NewRequest() - What does it do?
- 13:03First piece: Service Discovery
- 14:03Application Startup
- 15:37Service Validation - MustAddNamedAPI()
- 18:35Unit testing with hooks
- 19:41The HTTP call and all things surrounding it
- 29:22Climbing back out...








