May 2017: Generation dep
Meetup #39. Please RSVP at Meetup.
We get started at 6:30 pm.
Sponsors
Venue provided by Startup Edmonton.
Food sponsored by Bellstone Engineering.
Talks
Code Generation
Gerrit Renker gave a tour of code generation, starting with how other languages have done it — Lisp macros, Perl, Ruby, and Python's Jinja2 templates — before focusing on Go. In Go the usual route is go generate plus a generator, and the talk walked through tools like gocog, goa for micro-service APIs, go-swagger driven by OpenAPI, stringer for fmt.Stringer implementations, and enumer for enum Stringer/JSON methods. The tip of the month was easygen, which combines YAML input with text/template/html/template to emit code, and the talk showed how go generate discovers generators through //go:generate comments and the $GOFILE/$GOPACKAGE/$GOLINE environment variables.
Key points:
- Code generation is an old idea — Lisp's
defmacrois code that writes code. - Go's
go generateruns generators declared in//go:generatecomments. stringer,jsonenums, andenumergenerate Stringer and JSON methods for enums.goaandgo-swaggergenerate servers/clients from API DSLs and OpenAPI specs.easygenrenders YAML throughtext/template/html/template.- Generators receive
$GOFILE,$GOPACKAGE, and$GOLINE.
dep
Nathan Youngman introduced dep, Go's then-experimental dependency management tool, by first comparing it to the package managers other languages already had — pip, Bundler, npm, Maven, Composer, and Cargo — which let you decide when to upgrade, lock versions when things break, and opt into pre-releases. He traced Go's history from go get (2012), which fetches repositories by import path, to the vendor directory (2015), which copies third-party code into a project for a hermetic view of the world and protection from dependencies that move or disappear. dep init generates Gopkg.toml and Gopkg.lock; dep traverses your source for imports, still uses the vendor folder, and at the time had no central registry or flat namespace.
Key points:
- Other languages' package managers let you time upgrades and lock versions.
go getfetches packages straight from repositories by import path.- The
vendorfolder copies dependencies in, protecting against disappearing packages. dep initcreatesGopkg.toml(manifest) andGopkg.lock(lock file).depscans source imports and keeps usingvendor/.- No central registry or flat namespace in the early
depdesign.
Activities
- Kick the tires on dep, now that the manifest files are considered stable. Bring your laptop and a Go project if you have one.
Events
- Monthly Hack Day - Jun 3
- GopherCon July 12-15
- Edmonton Go Meetup - June