Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Implementing a command line client to GitHub in Go


Published on

My experience of building gh ( in Go

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Implementing a command line client to GitHub in Go

  1. 1. Implementing acommand line client toGitHub in GoOwen Ou@JingwenOwenOu
  2. 2. Agenda• Automating Git/GitHub workflows with gh• Introduction to Go• What I learnt from implementing gh withGo
  3. 3. What’s gh?• a command line tool that makes workingwith GitHub easier• gh pull• gh ci• gh fork• etc.
  4. 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. 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. 6. Demo
  7. 7. Implementation of gh• Implemented in Go• Fast (40% faster than Hub)• A single, statically linked binary with nodependencies (noVM needed!)• Unix, e.g., gh pull -b integration -hnew_feature
  8. 8. What’s Go?• Imperative• Object-oriented like• Concurrent• Compile to machine code• Created at 2009, v1.1.1
  9. 9. Ken Thompson• Founding father of Unix, see“Coders at work”• Bring in regular expressionto computing• Created grep in an evening• Designed UTF-8 on a dinerplacemat
  10. 10. Robert Griesemer• Native code generation forV8• Java HotSpotVM• StrongtalkVM (inspires theDartVM)
  11. 11. Rob Pike• First window system forUnix at Bell Labs• Plan 9• Co-Authors of “The UnixProgramming Environment”& “The Practice ofProgramming” with BrianKernighan• Newsqueak, Limbo:implementations of TonyHoare’s CSP
  12. 12. Why Go?• Why Learn Go? An interview with RobPike:
  13. 13. Hello Go
  14. 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. 15. Interfaces
  16. 16. The C10K Problem• The problem of optimizing socket serversoftware to handle a large number ofclients at the same time• C10k = concurrent ten thousandconnections• Linux pthreads (8MB),Windows (1MB),Coroutines (4k, e.g., Ruby Fibers)
  17. 17. 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
  18. 18. Goroutines
  19. 19. Channels
  20. 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 somuch simpler!)• Goroutines & channels (higher level APIs in net/http)
  21. 21. References• gh:• Code examples:• Go at Google:• Concurrency is not Parallelism:• Real world Go:
  22. 22. Q&A