22
Implementing a command line client to GitHub in Go Owen Ou @JingwenOwenOu

Implementing a command line client to GitHub in Go

  • 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

Page 1: Implementing a command line client to GitHub in Go

Implementing a command line client to

GitHub in GoOwen Ou

@JingwenOwenOu

Page 2: Implementing a command line client to GitHub in Go

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

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

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

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

Demo

Page 7: Implementing a command line client to GitHub in Go

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

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

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

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

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 13: Implementing a command line client to GitHub in Go

Hello Go

Page 14: Implementing a command line client to GitHub in 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

Page 15: Implementing a command line client to GitHub in Go

Interfaces

Page 16: Implementing a command line client to GitHub in Go

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

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

Goroutines

Page 19: Implementing a command line client to GitHub in Go

Channels

Page 20: Implementing a command line client to GitHub in Go

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 22: Implementing a command line client to GitHub in Go

Q&A