Statically typed • C syntax • Simple • Built to use multiple processors • Tools design for remote packages • Testing built in Language focused on Software engineering What is Go? Go features
here. Feel free to pick from the handful of pretty Google colors available to you. Make the subtitle something clever. People will think it’s neat. Variables
func main() { g := []string{"你好世界", … } rand.Seed(time.Now().Unix()) l := len(g) i := rand.Intn(l - 1) fmt.Printf("%s\n", greetings[i]) } Hello World How to Write Go
here. Feel free to pick from the handful of pretty Google colors available to you. Make the subtitle something clever. People will think it’s neat. Input
"strconv" ) func main() { i := flag.Int("lang", 0, " a number between 0 and 11") flag.Parse() a := []string{"你好世界", … } fmt.Printf("%s\n", a[i]) } Hello World How to Write Go
here. Feel free to pick from the handful of pretty Google colors available to you. Make the subtitle something clever. People will think it’s neat. Error Handling Part 1
here. Feel free to pick from the handful of pretty Google colors available to you. Make the subtitle something clever. People will think it’s neat. Finishing up the Program
language in which to get greeting.") flag.Parse() g := map[string]string{"Chinese":"你好世界", … } if r, ok := g[*l]; ok { fmt.Printf("%s\n", r) } else { log.Fatal("The language you selected is not valid.") } } Hello World How to Write Go
lang = ARGV[0] lang = "English" if lang == nil response = greet_list[lang] if response == nil puts "The language you selected is not valid." else puts response end Hello World How to Write Go
language in which to get greeting.") flag.Parse() greet_list := map[string]string{"Chinese":"你好世界", … } if result, ok := greet_list[*lang]; ok { fmt.Printf("%s\n", result) } else { log.Fatal("The language you selected is not valid.") } } Hello World How to Write Go
long. This is especially true for local variables with limited scope. Prefer c to lineCount. Prefer i to sliceIndex. https://github.com/golang/go/wiki/CodeReviewComments#variable-names
Licensed under CC BY-SA 3.0 via Wikimedia Commons - http: //commons.wikimedia.org/wiki/File:5-week-old_Golden_Retriever_puppy.jpg#/media/File:5-week-old_Golden_Retriever_puppy.jpg Go - d Ruby - dog Java - GoldenRetrieverWithASadFace
language in which to get greeting.") flag.Parse() g := map[string]string{"Chinese":"你好世界", … } if r, ok := g[*l]; ok { fmt.Printf("%s\n", r) } else { log.Fatal("The language you selected is not valid.") } } Hello World How to Write Go
language in which to get greeting.") flag.Parse() g := map[string]string{"Chinese":"你好世界", … } if r, ok := g[*l]; ok { fmt.Printf("%s\n", r) } else { log.Fatal("The language you selected is not valid.") } } Hello World How to Write Go
here. Feel free to pick from the handful of pretty Google colors available to you. Make the subtitle something clever. People will think it’s neat. Tooling Part 1
Go workspaces have 3 parts: ◦ src ◦ bin ◦ pkg • Most everything happens in src ◦ github.com/username/project • Set folder that contains src, bin, pkg to GOPATH ◦ export GOPATH=$HOME/go What is Go? Go Path
here. Feel free to pick from the handful of pretty Google colors available to you. Make the subtitle something clever. People will think it’s neat. Package
"你好世界", … } func Greet(language string) (string, error) { if r, ok := greetings[language]; ok { return r, nil } else { return "", errors.New("The language you selected is not valid.") } } Hello World How to Write Go
here. Feel free to pick from the handful of pretty Google colors available to you. Make the subtitle something clever. People will think it’s neat. Error Handling Part 2
"a language in which to get greeting.") flag.Parse() greet, err := helloworld.Greet(*l) if err != nil { log.Fatal(err) } fmt.Printf("%s\n", greet) } Hello World How to Write Go
"a language in which to get greeting.") flag.Parse() greet, err := helloworld.Greet(*l) if err != nil { if strings.Contains(err.Error(), helloworld.ErrorNotFound) { listLanguages() } else { log.Fatal(err) } } fmt.Printf("%s\n", greet) } Hello World How to Write Go
here. Feel free to pick from the handful of pretty Google colors available to you. Make the subtitle something clever. People will think it’s neat. What’s Next
"net/http" "github.com/tpryan/gosamples/helloworld" ) func main() { http.HandleFunc("/get", HandleGet) http.HandleFunc("/list", HandleList) log.Print(http.ListenAndServe(":8080", nil)) } Hello World How to Write Go
:= helloworld.Langauges() js, err := json.Marshal(list) if err != nil { handleError(w, err) return } sendJSON(w, string(js)) } Hello World How to Write Go
:= r.FormValue("language") greet, err := helloworld.Greet(lang) if err != nil { handleError(w, err) return } sendJSON(w, greet) } Hello World How to Write Go
here. Feel free to pick from the handful of pretty Google colors available to you. Make the subtitle something clever. People will think it’s neat. Concurrency
here. Feel free to pick from the handful of pretty Google colors available to you. Make the subtitle something clever. People will think it’s neat. Tooling Part 2
def getDistance(lat1, lon1, lat2, lon2) earth_radius = 3963 # in miles dLat = deg2rad(lat2 - lat1) dLon = deg2rad(lon2 - lon1) a = Math.sin(dLat/2)*Math.sin(dLat/2) + Math.cos(deg2rad(lat1))*Math.cos(deg2rad(lat2))*Math.sin(dLon/2)*Math.sin(dLon/2) c = 2 * Math.asin(Math.sqrt(a)) d = earth_radius * c end Haversine formula Why use Go (and why not)
Code in presentation is licensed under Apache: https://github.com/tpryan/SharedCode/ This work is licensed under a Creative Commons Attribution 2.0 Generic License.