Implementing a command line client to GitHub in Go
-
Upload
owen-ou -
Category
Technology
-
view
196 -
download
2
description
Transcript of Implementing a command line client to GitHub in Go
![Page 1: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/1.jpg)
Implementing a command line client to
GitHub in GoOwen Ou
@JingwenOwenOu
![Page 2: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/2.jpg)
Agenda
• Automating Git/GitHub workflows with gh
• Introduction to Go
• What I learnt from implementing gh with Go
![Page 3: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/3.jpg)
What’s gh?
• a command line tool that makes working with GitHub easier
• gh pull
• gh ci
• gh fork
• etc.
![Page 4: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/4.jpg)
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
![Page 5: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/5.jpg)
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
![Page 6: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/6.jpg)
Demo
![Page 7: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/7.jpg)
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
![Page 8: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/8.jpg)
What’s Go?
• Imperative
• Object-oriented like
• Concurrent
• Compile to machine code
• Created at 2009, v1.1.1
![Page 9: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/9.jpg)
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
![Page 10: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/10.jpg)
Robert Griesemer
• Native code generation for V8
• Java HotSpot VM
• Strongtalk VM (inspires the Dart VM)
![Page 11: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/11.jpg)
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
![Page 12: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/12.jpg)
Why Go?
• Why Learn Go? An interview with Rob Pike: http://www.youtube.com/watch?v=FTl0tl9BGdc
![Page 13: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/13.jpg)
Hello Go
![Page 14: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/14.jpg)
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
![Page 15: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/15.jpg)
Interfaces
![Page 16: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/16.jpg)
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)
![Page 17: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/17.jpg)
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
![Page 18: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/18.jpg)
Goroutines
![Page 19: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/19.jpg)
Channels
![Page 20: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/20.jpg)
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)
![Page 21: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/21.jpg)
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
![Page 22: Implementing a command line client to GitHub in Go](https://reader034.fdocuments.in/reader034/viewer/2022042816/55946cb71a28ab9e2b8b47ed/html5/thumbnails/22.jpg)
Q&A