Upload
owen-ou
View
203
Download
2
Embed Size (px)
DESCRIPTION
My experience of building gh (https://github.com/jingweno/gh) in Go
Citation preview
Implementing a command line client to
GitHub in GoOwen Ou
@JingwenOwenOu
Agenda
• Automating Git/GitHub workflows with gh
• Introduction to Go
• What I learnt from implementing gh with Go
What’s gh?
• a command line tool that makes working with GitHub easier
• gh pull
• gh ci
• gh fork
• etc.
A broken workflow• git checkout -b new_feature
• some code changes...
• git add .
• git commit -m “A comment”
• git push origin HEAD
• check CI status, oops..context switch
• create a pull request, oops...context switch
An optimized workflow• git checkout -b new_feature
• some code changes...
• git add .
• git commit -m “A comment”
• git push origin HEAD
• gh ci # prints build status
• gh pull # creates a pull request
Demo
Implementation of gh
• Implemented in Go
• Fast (40% faster than Hub)
• A single, statically linked binary with no dependencies (no VM needed!)
• Unix, e.g., gh pull -b integration -h new_feature
What’s Go?
• Imperative
• Object-oriented like
• Concurrent
• Compile to machine code
• Created at 2009, v1.1.1
Ken Thompson
• Founding father of Unix, see “Coders at work”
• Bring in regular expression to computing
• Created grep in an evening
• Designed UTF-8 on a diner placemat
Robert Griesemer
• Native code generation for V8
• Java HotSpot VM
• Strongtalk VM (inspires the Dart VM)
Rob Pike• First window system for
Unix at Bell Labs
• Plan 9
• Co-Authors of “The Unix Programming Environment” & “The Practice of Programming” with Brian Kernighan
• Newsqueak, Limbo: implementations of Tony Hoare’s CSP
Why Go?
• Why Learn Go? An interview with Rob Pike: http://www.youtube.com/watch?v=FTl0tl9BGdc
Hello Go
More about Go
• Compilation is very fast, gh has 1581 LOC, the build time is 0.77s
• Static typing & type inference
• Low level primitives uint, float64
• Garbage collected
• Pointers without pointer arithmetic
Interfaces
The C10K Problem
• The problem of optimizing socket server software to handle a large number of clients at the same time
• C10k = concurrent ten thousand connections
• Linux pthreads (8MB), Windows (1MB), Coroutines (4k, e.g., Ruby Fibers)
Goroutines
• Coroutines in Go, 4K, light weight threads
• Segmented stacks (a double linked lists)
• No stack-overflow
• Automatically scale to multiple-cores
• In the future, scale to multiple machines
Goroutines
Channels
Learning from gh• Right tool for the job - building a Unix tool
• Go’s compiler is freaking fast!
• Clarity and simplicity, less is more
• Go fmt
• Fast startup time, low memory usage
• Deploy a static library (making deployment so much simpler!)
• Goroutines & channels (higher level APIs in net/http)
References• gh: https://github.com/jingweno/gh
• Code examples: https://gist.github.com/jingweno/c00e973ade6d66b827fd
• Go at Google: http://www.infoq.com/presentations/Go-Google
• Concurrency is not Parallelism: http://vimeo.com/49718712
• Real world Go: https://gist.github.com/ungerik/3731476
Q&A