42
Are we ready to Go? Adam Dudczak Tomasz Jackowiak

Are we ready to Go?

Embed Size (px)

DESCRIPTION

Why we are submitting this talk? Because Go is cool and we would like to hear more about this language ;-). In this talk we would like to tell you about our experience with development of microservices with Go. Go enables devs to create readable, fast and concise code, this - beyond any doubt is important. Apart from this we would like to leverage our test driven habbits to create bulletproof software. We will also explore other aspects important for adoption of a new language.

Citation preview

Page 1: Are we ready to Go?

Are we ready to Go?Adam Dudczak

Tomasz Jackowiak

Page 2: Are we ready to Go?

Disclaimer

Page 3: Are we ready to Go?

Who we are?

Page 4: Are we ready to Go?
Page 5: Are we ready to Go?
Page 6: Are we ready to Go?

Why Go?

Page 7: Are we ready to Go?

Heka? Etcd? InfluxDb? JuJu?

Page 8: Are we ready to Go?
Page 9: Are we ready to Go?

Top 10?

Page 10: Are we ready to Go?

Not yet ;-)

Page 11: Are we ready to Go?

Why Go?

Page 12: Are we ready to Go?

Been there, done thatB, C, Java, JavaScript …

Page 13: Are we ready to Go?

• Class free, but object oriented

• Statically-typed - with elem. of duck typing

• Garbage collector

• Compiled - really fast compiler

• Open source from up to bottom (BSD license)

• Write once, run anywhere

Page 14: Are we ready to Go?

Show me the code!!!

Page 15: Are we ready to Go?

package main !import "fmt" !func main() { fmt.Println("Hello, World") }

Page 16: Are we ready to Go?

go run

Page 17: Are we ready to Go?

package main !import "fmt" !func swap(x, y string) (string, string) { return y, x } !func main() { a, b := swap("hello", "world") fmt.Println(a, b) }

Page 18: Are we ready to Go?

package main !import ( "fmt" "math" ) !type Vertex struct { X, Y float64 } !func (v *Vertex) Abs() float64 { return math.Sqrt(v.X*v.X + v.Y*v.Y) } !func main() { v := &Vertex{3, 4} fmt.Println(v.Abs()) }

Page 19: Are we ready to Go?

Microservice!?!

Page 20: Are we ready to Go?

package main !import ( "io" "net/http" ) !func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "hello, world\n") }) http.ListenAndServe(":8080", nil) }

Page 21: Are we ready to Go?
Page 22: Are we ready to Go?
Page 23: Are we ready to Go?

type Quote struct { BookTitle string `json:"book_title"` Sentence string `json:"sentence"` } !func NewQuotes(quotesFilePath string) ([]Quote, error) { fileContent, _ := os.Open(quotesFilePath) defer fileContent.Close() ! var quotes []Quote decoder := json.NewDecoder(fileContent) if err := decoder.Decode(&quotes); err != nil { return nil, errors.New("Failed to decode json") } return quotes, nil }

Page 24: Are we ready to Go?

type TwitterClient interface { Tweets(screenName string) []string } !!type FakeClient struct{} !func (fake *FakeClient) Tweets(screenName string) []string { return []string{"test tweet"} } !!func Test_shouldCreateNewPaolo(t *testing.T) { twitterClient := &FakeClient{} paolo := NewTweetingPaolo(twitterClient) assert.NotNil(t, paolo) }

Page 25: Are we ready to Go?

go routines

Page 26: Are we ready to Go?

func sleepySort(number int) { time.Sleep(time.Duration(number)) fmt.Println(number) } !func main() { arrayToSort := []int{12, 14, 3, 6, 1, 2} for _, val := range arrayToSort { sleepySort(val) } }

Page 27: Are we ready to Go?

func sleepySort(number int) { time.Sleep(time.Duration(number)) fmt.Println(number) } !func main() { arrayToSort := []int{12, 14, 3, 6, 1, 2} for _, val := range arrayToSort { sleepySort(val) } }

output: 12, 14, 3, 6, 1, 2

Page 28: Are we ready to Go?

func sleepySort(number int) { time.Sleep(time.Duration(number)) fmt.Println(number) } !func main() { arrayToSort := []int{12, 14, 3, 6, 1, 2} for _, val := range arrayToSort { go sleepySort(val) } }

Page 29: Are we ready to Go?

func sleepySort(number int) { time.Sleep(time.Duration(number)) fmt.Println(number) } !func main() { arrayToSort := []int{12, 14, 3, 6, 1, 2} for _, val := range arrayToSort { go sleepySort(val) } }

output: —

Page 30: Are we ready to Go?

func sleepySort(number int) { time.Sleep(time.Duration(number)) fmt.Println(number) } !func main() { arrayToSort := []int{12, 14, 3, 6, 1, 2} for _, val := range arrayToSort { go sleepySort(val) } time.Sleep(1 * time.Second) }

output: 1, 2, 3, 6, 12, 14

Page 31: Are we ready to Go?

channels

Page 32: Are we ready to Go?

func sleepySort(number int, sort chan<- int) { time.Sleep(time.Duration(number)) sort <- number } !func main() { arrayToSort := []int{12, 14, 3, 6, 1, 2} sort := make(chan int) ! for _, val := range arrayToSort { go sleepySort(val, sort) } ! for i := 0; i < len(arrayToSort); i++ { fmt.Println(<-sort) } }

Page 33: Are we ready to Go?

quote := make(chan Quote) go func() { quote <- localPaolo.RandomQuote() }() go func() { quote <- twittingPaolo.RandomTweet() }() go func() { quote <- wisePaolo.RandomHeartQuote() }() !for i := 0; i < 3; i++ { fmt.Println(<-quote) }

Page 34: Are we ready to Go?

go get github.com/tjackowiak/coelho

Page 35: Are we ready to Go?

Coding standards

Page 36: Are we ready to Go?

gofmt & co

Page 37: Are we ready to Go?

github / Drone.io / coveralls

Page 38: Are we ready to Go?

Are we ready to Go?

Page 39: Are we ready to Go?

Pros• Standing on the shoulders of giant

• Concise and readable - maybe even fun ;-)

• Simple and powerful tooling (go run | install | …)

• Really nice dependency management

• Language spec - with promise of backward compatibility

Page 40: Are we ready to Go?

Cons• Relatively new language

• There is still space to improve how GC works

• Not a JVM language

Page 41: Are we ready to Go?

It is definately worth trying ;-)

Page 42: Are we ready to Go?

@maneo, @kevorin

Questions?