Go At Work

Bryan Liles
December 18, 2014

Go At Work

You know how to program Go. How do you program Go at work?

Bryan Liles

December 18, 2014

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

58 slides
  1. digitalocean.com package main import "github.com/go-martini/martini" func main() { m :=

    martini.Classic() m.Get("/", func() string { return "Hello world!" }) m.Run() }
  2. digitalocean.com package main import ( "fmt" "net/http" "github.com/codegangsta/negroni" ) func

    main() { mux := http.NewServeMux() mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "Hello world!") }) n := negroni.Classic() n.UseHandler(mux) n.Run(":3000") }
  3. digitalocean.com package main import ( "fmt" "net/http" ) func handler(w

    http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello world!") } func main() { http.HandleFunc("/", handler) http.ListenAndServe(":3000", nil) }
  4. digitalocean.com package main import ( "fmt" "net/http" "github.com/gorilla/mux" ) func

    main() { r := mux.NewRouter() r.HandleFunc("/", homeHandler) http.Handle("/", r) http.ListenAndServe(":3000", nil) } func homeHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "Hello world!") }
  5. digitalocean.com “You wouldn’t go around picking stuff off the street

    and eating it. Why do so with your dependencies?”
  6. digitalocean.com import ( "database/sql" "doge/log" "doge/notify" "fmt" "os" "services/migration" "time"

    _ "github.com/go-sql-driver/mysql" "github.com/ianschenck/envflag" )
  7. digitalocean.com import ( "database/sql" "fmt" "os" "time" "doge/log" "doge/notify" "services/migration"

    _ "github.com/go-sql-driver/mysql" "github.com/ianschenck/envflag" )
  8. digitalocean.com func TestSquare(t *testing.T) { expected := 25 got :=

    square(5) if got != expected { t.Errorf("expected %d, got %d", expected, got) } }
  9. digitalocean.com func TestSquare0(t *testing.T) { expected := 0 got :=

    square(0) if got != expected { t.Errorf("expected %d, got %d", expected, got) } }
  10. digitalocean.com func TestSquare(t *testing.T) { cases := []struct { arg

    int expected int }{ {5, 25}, {0, 0}, {-1, 1}, } for i, c := range cases { got := square(c.arg) if got != c.expected { t.Errorf("case %d: expected %d, got %d", i, c.expected, got) } } }

More Decks by Bryan Liles

Other Decks in Programming