golang getting started

14
Golang Getting started Not a talk – reference deck

Upload: harshad-patil

Post on 16-Feb-2017

333 views

Category:

Engineering


2 download

TRANSCRIPT

Page 1: Golang getting started

GolangGetting started

Not a talk – reference deck

Page 2: Golang getting started

What is go?•  Statically-typed language //resembles C• Concurrency• Garbage collection• Type safety – with some dynamic typing• Fast compilation • Remote package management • Great builtins

… C + some Awesome stuff

Page 3: Golang getting started

The Mandatory

• http://play.golang.org/p/OccSs5jC9Y

package main

import "fmt”

func main() {fmt.Println("Hello World!")

}

Page 4: Golang getting started

Built for networks

• A simple server

package main

import "fmt” Import "net/http”

func hello(w http.ResponseWriter, r *http.Request) {fmt.Fprint(w, "Hello Client") //write response

}func main() {

http.HandleFunc("/", hello //attach handler http.ListenAndServe(":8080”, nil) //start server}

Page 5: Golang getting started

ConcurrencyGreen Threading like python – goroutines

no Gil like limitationshttps://gobyexample.com/goroutines

Utilize multiple coresgoroutines can be run on multiple threads

Page 6: Golang getting started

External pacakgesgo get <package_name>e.g. go get github.com/goibibo/gorpc

Installs to your specified patheasily install forks

Also checkout godep, https://github.com/tools/godep for better managing dependencies of your project

Page 7: Golang getting started

Builtins

Just checkout https://golang.org/pkg/

You can see the source at https://golang.org/src/

Page 8: Golang getting started

Start- tour• Take the tour, complete it tour.golang.org• Check http://openmymind.net/The-Little-Go-Book/ for a light introduction

Page 9: Golang getting started

Start- install

• Install locally (1.4 for now)• http://golang.org/doc/install• Or the docker image if you prefer https://hub.docker.com/r/google/golang/

Page 11: Golang getting started

Start – some more stuff

• Organising Go code by David Crawshaw, presented at Google I/O 2014.• Contributing to Open Source Git Repositories in Go by Katrina Owen.

Page 13: Golang getting started

Dev Environment – tools• go fmt• golint

Page 14: Golang getting started

Right tool for the right problem…• Good for

Backend APIs Process Heavy stuff Non blocking IO, service calls

• Not so great Templating ORMs

… But still growing