Go for Web Developers Workshop Part II

Meetup #55. Please RSVP at Meetup.

We get started at 6:30 pm.

Sponsors

Venue provided by Startup Edmonton.

Food sponsored by Bellstone Engineering.

Workshop

Part II of the Go for Web Developers workshop, taught by Chris Olsen, turned the weather library from Part I into a small web API. It covered configuring an app with flag (including defaults and -help), handling requests with http.Handler/http.HandlerFunc, and injecting a weather service through a handler struct. The workshop showed content negotiation using the Accept header to return either JSON (encoding/json) or rendered HTML (html/template), reading lat/lng query parameters, and pulling weather from the github.com/edmontongo/darksky service. It finished by refactoring away a global service variable in favour of interfaces and testing the API with a mock service and httptest.

Key points:

  • Builds a web API on top of the Part I Dark Sky library.
  • Configures the app with flag (defaults, secrets, -help).
  • Uses http.Handler/http.HandlerFunc and a handler struct to inject dependencies.
  • Negotiates JSON vs HTML via the Accept header.
  • Serves lat/lng query parameters through the weather service.
  • Refactors the global service into an interface for testability.
  • Tests handlers with a mocked API and httptest.

Instructor: Chris Olsen

News

Talks