Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction to Go language

A primer to Google's Go Language, the presentation is designed to help kickstart developers to use the new language.

  • Login to see the comments

Introduction to Go language

  1. 1. Introduction to Go Language GDGDEVFESTBAGUIO -CAR 2014 UNIVERSITY OF BAGUIO TZAR C. UMANG ICT DIRECTOR –HIVE INC.
  2. 2. Flow of discussion Requirements Introduction Basics Sample Deployment
  3. 3. Requirements Development Software Development Kit and Test Environment You can use Appengine’sGo SDK: https://cloud.google.com/appengine/downloads Python 2.7 (please don’t use the newest version) IDE You can use Sublimetxtand notepad++ If your on the cloud you can use Github’sonline IDE Pushing files when Deploying Git: http://git-scm.com
  4. 4. Requirements Development Servers Highly recommend Google’s Appenginefor Go Language You can also use Openshift’sGo Language Environment, but you will not have access to Appengine’sfunctionalities Deployment You can use Appengine+ Cloudcomputeof Google Or OpenshiftBig Gear
  5. 5. Young Language Created by: Robert Griesemer, Ken Thompson, and Rob Pike (Googlers) in late 2007 Brought to public in 2009 A new systems programming languagefor the past 10 years + It is fastto develop, compileand run Answer to hardware’s limitations today, yet future proofing your system, where the language handles routine and memory management Funand Easymaking developmentmore productiveand we don’t use semicolons “;” Uses goroutines, a lightweight communicating processes and its concurrent, multiplexing of it onto threads is done automatically Has a good garbage collection, it is efficient and low in latency
  6. 6. Basics -“Hello World” package helloworld import ( "fmt" "net/http" //http handler package ) funcinit() { http.HandleFunc("/", handle) } funchandle(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "<html><body><b>Hello World</b></body></html>") }
  7. 7. Basics Comments Uses /**/ or // // for line by line comment /**/ for large chunk disabling of function or a big header credit on your code
  8. 8. Basics Formatting Indention is just like any other IDE for any PL tab works for them gofmthandles alignment on you code Parenthesis Go uses lesser parenthesis Structures like if, for and switch don’t require it Operator precedence hierarchy is shorter and clearer x<<8 + y<<16 //spaces implies what it means
  9. 9. Basics Semicolons “ ; “ We don’t usually use it to terminate a line just like python Mostly used to separate clauses of for –loops and the like Making codes cleaner on the eye
  10. 10. Basics If –statement It looks as simple as this if a > 1 { return b } It also accept initialization statements, to setup a local variable if err := datastore.Get(c, key, &b); err != nil { return err }
  11. 11. Basics Loop Unified for and while, there is no do-while For for init; condition; post { } While for condition { } For(;;) for { } No comma operator and “+ +” and “--” are statements not expression //Reversea fori,j:=0,len(a)1;i<j;i,j=i+1,j1{ a[i],a[j]=a[j],a[i] } To run multiple variables you need to use assignments
  12. 12. Basics Switch Go uses a more general implementation of switches Expressions don’t need to be constants or even integers Cases are evaluated top to bottom until a match is found And if switch has no statement it switches to “true” Making it possible to write if-else-if-else-if-else chain as a switch
  13. 13. Basics Switch funcunhex(cbyte)byte{ switch{ case'0'<=c&&c<='9': returnc'0' case'a'<=c&&c<='f': returnc'a'+10 case'A'<=c&&c<='F': returnc'A'+10 } return0 }
  14. 14. Basics Switch Cases can be presented into commas as well funcrunOver(cbyte)bool{ switchc{ case'','?','&','=','#','+','%': returntrue } returnfalse }
  15. 15. Basics Types It uses the regular int, float, string Booleans (&& “and”, || “or”, ! “not”) Explicitly sized typesthe likes of int8, float64 Unsigned integers, uint, uint32
  16. 16. Basics Strings It is built in, these are immutable values not just arrays of bytes values. You can’t change a string variable once it is built Though you can use snippets to change or to reassign string variables s:="hello" ifs[1]!='e'{os.Exit(1)} s="goodbye" varp*string=&s *p="ciao"
  17. 17. Basics Arrays Declared this way vararrayOfInt[10]int; They are like strings with values though mutable Arrays holds values in Go making it as meaningful as a string, not like with other language such as C where arrays are pointers
  18. 18. Basics Pointers We have them but they are limited No pointer arithmetic Easier for garbage collection
  19. 19. Basics Database supported MySQL, Oracle, DB2 MongoDB, NoSQL Mobile App Delivery Supported Platform and Framework (Based on our testing) Intel XDK Phonegap
  20. 20. Basics Libraries OS, I/O, files math (sin(x) etc.) strings, Unicode, regular expressions reflection command-line flags, logging hashes, crypto testing (plus testing tool, gotest) networking, HTTP, RPC HTML (and more general) templates And growing… Documentation and complete list here: http://golang.org
  21. 21. Other Resources http://golang.org/pkg/ (package docs) http://golang.org/src/ (source code)
  22. 22. Requirements Development Software Development Kit You can use Appengine’sGo SDK: https://cloud.google.com/appengine/downloads Python 2.7 (please don’t use the newest version) IDE You can use Sublimetxtand notepad++ If your on the cloud you can use Github’sonline IDE Pushing files Git: http://git-scm.com
  23. 23. Requirements Development Servers Highly recommend Google’s Appenginefor Go Language You can also Openshift’sGo Language Environment, but you will not have access to Appengine’sfunctionalities Deployment You can use Appengine+ Cloudcomputeof Google Or OpenshiftBig Gear
  24. 24. THANK YOU!!! For Questions and Tutorials you may join the group “Philippine Gophers” in FB and G+ Or add me in: fb.com/tzarumang twitter.com/definitelytzar plus.google.com/tzarumang Presentation is based from: golang.org Chris Lupo’sThe Go Programming Language

×