go: Dropped from 30 to 2 servers and the second server was used only for redundancy. CPU utilization dropped to less than 5%. Memory usage dropped. Only a "few hundred KB's of memory (on startup) vs our Rails apps which were ~50MB (on startup)". Iron.IO - How We Went from 30 Servers to 2: Go (http://blog.iron.io/2013/03/how-we-went-from-30-servers-to-2-go.html) GopherCon 2014 From Node.js to Go by Kelsey Falter (https://www.youtube.com/watch?t=21&v=mBy20FgB68Q)
// Snippet extracted from: arith_386.s // This file provides fast assembly versions for the elementary // arithmetic operations on vectors implemented in arith.go. // func mulWW(x, y Word) (z1, z0 Word) TEXT ·mulWW(SB),NOSPLIT,$0 MOVL x+0(FP), AX MULL y+4(FP) MOVL DX, z1+8(FP) MOVL AX, z0+12(FP) RET
- unless you are a programmer, Rob Pike package main ; import "fmt" ; func main() { fmt.Println("Hello, "); } $ go fmtmain.go Annoying at start Fucking good at the end go fmt could be easily integrated with Vim, Sublime Text or Atom package main import "fmt" func main() { fmt.Println("Hello, ") } Run
3.14 b := "some string" var c float32 = 3.14 var d string = "some string" fmt.Println("a:", a) fmt.Println("b:", b) fmt.Println("c:", c) fmt.Println("d:", d) } Run
"time" ) func main() { rand.Seed(time.Now().Unix()) i := rand.Intn(1e6 + 1) fmt.Println("i:", i) switch { case i > 1 && i < 1000: fmt.Println("Between one and thousand") case i > 1000 && i < 1e6: fmt.Println("Between hundred and 1 million") default: fmt.Println("Too huge ! Lucky guy :)") } } Run
func(int) int { return func(number int) int { return n * number } } func main() { ten := multiplicator(10) two := multiplicator(2) log.Println("16 times 10:", ten(16)) log.Println("45 times 2:", two(45)) } Run
struct { Name string } func (p Person) changeName(name string) { p.Name = name } func main() { a := Person{Name: "Georges"} b := &Person{Name: "Martin"} a.changeName("Justin") b.changeName("Justin") fmt.Println("A:", a) fmt.Println("B:", b) } Run
walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck James Whitcomb Riley Go deals with polymorphism through the concept of interface If a struct implements all the methods de ned in the interface, it is compatible with it No coupling between foreign packages Interface should be considered as pointer
Count int func main() { values := []interface{}{1, "fwefwefw", Count(9)} for _, value := range values { switch value.(type) { case int: fmt.Printf("Value is a int %d\n", value) case string: fmt.Printf("Is a string:%s\n", value) case Count: fmt.Printf("Is a Count:%d\n", value) } } } Run
Martini (Re ection) HTTP Midlewares based framework: negroni Abuse of HTTP middlewares My recommandation to start : pat (https://github.com/bmizerany/pat) (muxer), negroni (https://github.com/codegangsta/negroni) (HTTP middlewares) and gorilla (www.gorillatoolkit.org/) packages (context, sessions)
for distributed applications for developers and sysadmins hugo (http://gohugo.io/) : A Fast and Modern Static Website Engine limetext (http://limetext.org/) : Lime Text is a powerful and elegant text editor primarily developed in Go that aims to be a Free and open-source software successor to Sublime Text. nes (https://github.com/fogleman/nes) : A Nintendo Entertainment System (NES) emulator written in Go bolt (https://github.com/boltdb/bolt) : A low-level key/value database for Go. cayley (https://github.com/google/cayley) : A graph database with support for multiple backends.