Implementing a
command line client to
GitHub in Go
Owen 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 (noVM 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 HotSpotVM
• StrongtalkVM (inspires the
DartVM)
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

Implementing a command line client to GitHub in Go

  • 1.
    Implementing a command lineclient to GitHub in Go Owen Ou @JingwenOwenOu
  • 2.
    Agenda • Automating Git/GitHubworkflows with gh • Introduction to Go • What I learnt from implementing gh with Go
  • 3.
    What’s gh? • acommand line tool that makes working with GitHub easier • gh pull • gh ci • gh fork • etc.
  • 4.
    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
  • 5.
    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
  • 6.
  • 7.
    Implementation of gh •Implemented in Go • Fast (40% faster than Hub) • A single, statically linked binary with no dependencies (noVM needed!) • Unix, e.g., gh pull -b integration -h new_feature
  • 8.
    What’s Go? • Imperative •Object-oriented like • Concurrent • Compile to machine code • Created at 2009, v1.1.1
  • 9.
    Ken Thompson • Foundingfather of Unix, see “Coders at work” • Bring in regular expression to computing • Created grep in an evening • Designed UTF-8 on a diner placemat
  • 10.
    Robert Griesemer • Nativecode generation for V8 • Java HotSpotVM • StrongtalkVM (inspires the DartVM)
  • 11.
    Rob Pike • Firstwindow 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
  • 12.
    Why Go? • WhyLearn Go? An interview with Rob Pike: http://www.youtube.com/watch? v=FTl0tl9BGdc
  • 13.
  • 14.
    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
  • 15.
  • 16.
    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)
  • 17.
    Goroutines • Coroutines inGo, 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
  • 18.
  • 19.
  • 20.
    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)
  • 21.
    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
  • 22.