Intro To GoLang

Case Talbot
@nikolawannabe

Who am I?

  • Software development lead at Smashwords

  • Geek, nerd, etc.

  • Book afficianado

  • Writing Go for about a year, but I have no special knowledge.  I’m just a programmer who likes Go. 

  • Starting a Go meetup in Davis!

Go History

Created by Robert Griesemer, Rob Pike, and Ken Thompson

  • Development began at Google in 2007.

  • Officially announced and become a public open source project in 2009.

  • Version 1.0 of Go was released March 28, 2012.

  • The most recent version, 1.3, was released June 18, 2014.

  • Go 1.4 code freeze is September 1, 2014; release is December 1, 2014.
  • Lately, there's a new minor version every 6 months.

Go in the Wild

It’s a real thing!

  • Gov.uk router

  • Google of course, with YouTube

  • Soundcloud, with over a dozen services and repositories in Go

  • Heroku with a distributed data store

  • Bitly, with queue consumers and other things

  • At Smashwords, we use it for queue consumers, reporting, and will be using it for more things in the future.

Build Something With Go

  • Go is statically typed like C or C++.

  • It is compiled, not a scripting language like Ruby or Python.

  • UTF-8 support is the default

    • This is fine.  No snowmen allowed in your variable names per @golang.  

  • The output of a go build is a statically linked binary.

  • Go can compile to binaries for Windows, OSX, and Linux, and this is built into the build system by default.

  • Method and field exportation is defined by capitalization.

Go Has a Built-In Toolchain

Run go {command} for...

  • build       

    • compile packages and dependencies

  • install     

    • compile and install packages and dependencies.  "Installing" means to dump the outputs in the bin directory.

  • get

    • download and install packages and dependencies to your workspace as defined by your imports.

  • fmt         

    • format your files sanely and without fuss.

  • test       

    • test packages.  This runs with the package in the source directory of the package, and puts the package under test in scope as if you were local to the package.  By convention then, test data belongs in a testdata directory in the package directory.

  • vet         

    • run go tool vet on packages to validate that you aren't doing stupid things that the compiler will let you do, but are probably dumb.

  • and other things...

Oh, workspaces?!

Yes, go basically enforces a particular directory structure for any projects more than trivial.


bin/
project1binary
project2binary
pkg/
linux_amd64/
etc..
src/
github.com/nikolawannabe/
project1/
project2/
code.google.com/p/goauth2/
somedependency/

Go is Object-Oriented, Jim

But not as we know it!

  • No operator overloading

  • No method overloading

  • No subclassing

  • No constructors

  • No exceptions

    • Well, mostly...

  • No classes!



Which means it also has no generics :(

Instead We Get

Do we really need to learn another language?

If you:

  • Like cross platform languages

    • Like C, Java or Ruby or Python

  • Like languages that don’t run on a virtual machine

    • Like C, Ruby or Python

  • Like static typing

    • Like C

  • Like modern languages where you don’t have to manage your memory or deal with 25 years of language design crumped into one unholy core of terror (*cough C++ 11*)

    • ...

  • Like fast languages


Well, then.  Yeah.

Favorite Features

Favorite Packages

Gotchas

Demo

Let's make a thing we can actually use.

A server that listens for requests to generate epubs for a given rss url.

https://github.com/nikolawannabe/epub
https://github.com/nikolawannabe/feedepub

Where to Go Next?

  1. Take the interactive tour.

  2. Install Go and learn how to set up your workspace.

  3. Read the Go FAQs.

  4. Read Effective Go.

  5. Fall in love with godoc.

  6. Make stuff!