Golang 140118232950
Golang 140118232950
UTTAM GANDHI
CONNECT WITH UTTAM ON LINKEDIN
About Me
C, C++ Developer for last 11 years
Hands on in Javascript, python, ruby, MongoDB
Working with Synerzip for Since July 2011 on a C++
project
History of Go
Robert Griesemer, Rob Pike and Ken Thompson
Why Go
Without go one has to choose between efficient
C++
Java
Javascript
Go
Typesafe
Garbage
Collection
Compilation
Slow
Slow
NA
Very Fast
Concurrency
Ease of
programming
Efficiency
Highest
Slow
Slowest
Close to C++
Hello World
// hello.go!
package main!
import (!
"fmt!
)!
func main() { !
fmt.Println("Hello World)!
}!
Sample function
package main!
Import fmt!
func split(sum int) (x, y int) {!
x = sum * 4 / 9!
y = sum - x!
return!
}!
func main() {!
var x, y, z int!
fmt.Println(x,y,z)!
fmt.Println(split(17))!
}!
export GOPATH=$HOME/go!
go install hello!
hello!
go test sum!
Object Oriented Go
No classes, no inheritance
go has duck typing
structs are used for custom types, aggregation
Interfaces, abstract type has methods
Any custom type having same methods as interface
interface
package main!
import (!
"fmt"!
)!
type Printer interface {!
Print()!
}!
func (f MyFloat) Print() {!
!fmt.Println(f);!
}!
func main() {!
var a Printer !
f := MyFloat(5.5)!
a = f!
Features 1/2
Garbage collection
Concurrency
Packages
Types
Features 2/2
Slices (array) http://tour.golang.org/#31
Maps http://tour.golang.org/#39
Function closures http://tour.golang.org/#43
Struct methods http://tour.golang.org/#50
Methods cannot be defined on basic types
Interfaces http://tour.golang.org/#53
Error http://tour.golang.org/#55
Concurrency
go routines
Lightweight thread like routine (may be one or more thread)
Channels and Buffered Channel
Useful for sync between go routines
Send and receive to channel is blocking ( no sync needed)
Range and close
Range used iterating over channel
Close used by sender after sending all values
Select
Lets goroutine waits on multiple communication operations
JSON and Go
type Message struct {!
Name string!
Body string!
Time int64!
}!
m := Message{"Alice", "Hello",
1294706395881547000}!
b, err := json.Marshal(m)!
b ==
[]byte(`{"Name":"Alice","Body":"Hello","Time"
:1294706395881547000}`)!
Web Server
Creating a webserver is childs play in Go, (if the child
knows programming J
A sample is available here
Web Server -- http://tour.golang.org/#59
Go In Production
Google is using in production for
http://golang.org
Vitess system for large-scale SQL installations
Download server dl.google.com
Iron.io
Nokia
SoundCloud
http://go-lang.cat-v.org/organizations-using-go
My Opinion About Go
In my opinion Go is very useful for server side
References
FAQ http://golang.org/doc/faq
Installation http://golang.org/doc/install
Code http://golang.org/doc/code.html
Videos
http://blog.golang.org/go-videos-from-googleio-2012
Tour http://tour.golang.org/
Efficiency BM - JSON Benchmarks
References
http://www.javaworld.com/article/2080935/
scripting-jvm-languages/go-google-go-a-languageon-full-throttle.html
http://blog.golang.org/json-and-go
http://www.drdobbs.com/open-source/gettinggoing-with-go
http://www.drdobbs.com/open-source/why-not-go/
240005062
http://www.jellolabs.com/blog/why-golang-isready-for-early-stage-startups.html
References
http://stackoverflow.com/questions/11462046/what-is-
the-niche-of-go-lang
https://code.google.com/p/go-wiki/wiki/
SuccessStories#
http://stackoverflow.com/questions/12168873/crosscompile-go-on-osx
http://matt.aimonetti.net/posts/2012/11/27/real-lifeconcurrency-in-go/
http://www.golang-book.com/10
http://matt-welsh.blogspot.in/2013/08/rewriting-largeproduction-system-in-go.html