Upgrade to Pro — share decks privately, control downloads, hide ads and more …

#golang

Avatar for Brian Smith Brian Smith
February 20, 2014

 #golang

An introduction to Go

Avatar for Brian Smith

Brian Smith

February 20, 2014

Other Decks in Programming

Transcript

  1. Why Go? • Simple but powerful concurrency model • Garbage

    collected yet performant (memory management is hard, GC is slow… Go is neither) • Small language spec but powerful expressiveness (simple OO model, functional, rich native types) • Tools! Perhaps the best built-in toolset of any language I’ve ever encountered (fmt, doc, build, install, get, etc)
  2. Installation • Install Go: • brew install go • Setup

    your GOPATH: • mkdir -p ~/Go/{src,bin,pkg} • export GOPATH=/Users/<username>/Go • export PATH=$GOPATH/bin:$PATH
  3. Let’s Make a Project • Workspaces, think differently (mostly) •

    cd ~/Go • mkdir -p src/github.com/<username>/wcg • cd !$
  4. … to fetch status codes! We want to check a

    list of URLs for response statuses to monitor health.! status.go! domains.txt! go run status.go path/to/domains.txt
  5. Notes • package main / func main • import (…)

    • type Name struct {…} • functions • exported vs private • multiple return values • for / range / _
  6. That works, but lame sauce… We’re waiting on every request

    before proceeding to the next. Let’s just fire ‘em all and deal with them as they return. But threads are hard, right? status.go go run status.go path/to/domains.txt
  7. Notes • goroutines • channels • error into struct •

    no more range, traditional `for` • psssh, concurrency is easy…
  8. Now what? • Ok, I’m ready to go, let’s package

    this guy up! (run vs. build vs. install and architecture cross-compiling) • Diverging formatting styles? Nope! (fmt) • Package management (*sad trombone*) • goroutines vs process/thread model (multiplexing, GOMAXPROCS, and NumCPU)
  9. References Go documentation is amazing! • Interactive Tour: http://tour.golang.org/ •

    Gentle intro: http://golang.org/doc/code.html • The real docs: http://golang.org/doc/effective_go.html • The spec: http://golang.org/ref/spec • Ongoing blog content: http://blog.golang.org/ • The example: https://gist.github.com/Lytol/9110081