Go aims to combine the safety and performance of a statically typed compiled language with the expressiveness and convenience of a dynamically typed interpreted language. - Rob Pike Monday, August 5, 13
History • End of 2007 start by Rob Pike, Ken Thompson and Robert Griesemer. • Implementation started after design in mid 2008. • Going public in November 2009. • Release of Go 1 in March 2012. Monday, August 5, 13
Reduce Energy Costs and Go Green 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 Monday, August 5, 13
Success Stories • Airbrake: From Ruby to Go • Go at Heroku • Organizations using Go: Canonical, BBC, Heroku, SmugMug, SoundCloud, Bitly.... Monday, August 5, 13
Type Assertion type Stringer interface { String() string } var value interface{} // Value provided by caller. switch str := value.(type) { case string: return str case Stringer: return str.String() } Monday, August 5, 13
Real World Usage • 10+ Tables • A lot of CRUD operations in different methods. • We want performance for hot spots, for other situations, we don’t. Monday, August 5, 13
type Staff struct { ! Id int64 `field:"id"` ! Name string `field:"name"` ! Gender string `field:"gender"` ! StaffType string `field:"staff_type"` ! Phone string `field:"phone"` } put model fields in struct Monday, August 5, 13
Reflection • Retrieve information dynamically (in the runtime): • Type Name • Struct Fields • Struct Tag • Struct Field Type • Function Type • ....etc Monday, August 5, 13
Struct Metadata type Staff struct { ! Id int64 `json:"id"` ! Name string `json:"name"` ! Gender string `json:"gender"` ! StaffType string `json:"staff_type"` ! Phone string `json:"phone"` } Type Name Fields Field Type Struct Tag Tag Key Monday, August 5, 13
Reflection import "reflect" staff := new(Staff) // get reflection value of pointer t := reflect.ValueOf(staff) // get reflection value t := reflect.ValueOf(staff).Elem() Monday, August 5, 13