SlideShare a Scribd company logo
coding in GO
Monthly meetup November 2015 NSBM
Raveen Perera
History
Created by Robert Griesemer, Rob Pike, Ken Thompson
Developed in 2007 and first stable open source release 2009 (BSD)
GO
Fast, compiled language, directly to machine code and spearheaded by
What’s so special about GO ?
Compilation
Very fast compilation (seconds)
No VM needed
GOs Assembler
Tools
go fmt go vet
go test go doc
Concurrency
Asynchronous processes called
GOroutines
Channels used to pass data
between routines
Standard Library
net/http
flag
encoding/json encoding/xml
Simplicity in Syntax
GO stands between C and Python
Highly influenced by many other
popular programming languages
Deployment
Can be compiled to a single binary
file
You can build and compile in your
host or server
Let’s dive in
Download and install GO
https://golang.org/dl/
Download and install Sublime Text 3
http://www.sublimetext.com/3
and install GOSublime plugin
https://github.com/DisposaBoy/GoSublime
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello World!")
}
$ go run helloworld.go
The Basics
https://golang.org/ref/spec
Variables
var age int = 40
name := “John Doe”
const pi float64 = 3.14
strings “ ” or ` `
bool true false
+ - * / %
&& || ! == != >= <=
Loops
for i := 0; i < count; i++ {
}
for i, value := range array {
}
for i <= 10 {
i++
}
Conditions
if i > 10 {
} else if i > 5 {
} else {
}
switch grade {
case 75: fmt.Println("A")
default: fmt.Println("nothing")
}
Arrays
var myArray[5] int
myArray := [5]int {1,2,3,4,5}
mySlice := []int {1,2,3,4,5} //Slice has no size declaration
mySlice2 := mySlice[3:5]
slice := make([]int, 5, 10)
slice = append(slice,0,1)
Maps
Just like dictionaries in python
grades := make(map[string] int)
grades[“John”] = 80
delete(grades,”John”)
Functions
func myFunc(number int) int {
return number + 5
}
func myFunc(number int) (int,int) {
return number + 5, number +6
}
Executes after the enclosing function
defer myFunc()
Undefined number of variables
func uParams(args ...int) int {
}
func divide(num1 int, num2 int) int {
defer func() {
fmt.Println(recover())
}()
answer := num1/ num2
return answer
}
func divide() {
defer func() {
fmt.Println(recover())
}()
panic(“sending to recover”)
}
Functions - defer() and panic()
Closure
Declaring a function inside another
func main() {
myfunc := func() int {}
myfunc()
}
Pointers
x := 8
changeX(&x)
func changeX(x *int){
*x = 10
}
myPointer := new(int)
X
memory address
(0xc0820022b0)
Structures
Go is not object oriented
type Circle struct {
var radius float64
var name string
}
myCircle = Circle{name:”circle1” , radius:5}
func (circle Circle) area() float64 {
return circle.radius*circle.radius*3.14
}
Handling Concurrency
GORoutines
Not expensive as threads
Multiple Goroutines without cost
Channels
GORoutines reads and writes values from an to
channels to communicate
https://golang.org/pkg/sync/atomic/
GO http
Route
Handles the requests and determines which function should
handle that request
Handler
The function that executes when a request is made
Server
The networking code which handles the requests and routes
(Serve mux) multiplexer, http request router
Simple http server
Simple respond writer
package main
import "net/http"
func main() {
http.HandleFunc("/", homeHandler)
http.ListenAndServe(":8100", nil)
}
func homeHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("අ◌ායුෙබ◌ා◌් වන්"))
}
Gorilla Toolkit
Gorilla Mux
$ go get github.com/gorilla/mux
simple buffer writer
Gorilla sessions
$ go get github.com/gorilla/sessions
GO Frameworks Toolkits and Micro Frameworks
https://github.com/golang/go/wiki/LearnServerProgramming
Who uses Go
https://github.com/golang/go/wiki/GoUsers
Thank You
Monthly meetup November 2015 NSBM
Raveen Perera

More Related Content

What's hot (20)

PDF
Go concurrency
siuyin
 
PDF
Golang design4concurrency
Eduardo Ferro Aldama
 
PDF
Happy Go Programming Part 1
Lin Yo-An
 
PDF
Concurrency with Go
Frank Müller
 
PDF
Implementing Software Machines in Go and C
Eleanor McHugh
 
PDF
Let's golang
SuHyun Jeon
 
PPTX
Go Language Hands-on Workshop Material
Romin Irani
 
PDF
Clojure+ClojureScript Webapps
Falko Riemenschneider
 
PDF
Defer, Panic, Recover
Joris Bonnefoy
 
PDF
Introduction to go language programming
Mahmoud Masih Tehrani
 
ODP
Hands on Session on Python
Sumit Raj
 
ODP
To Infinity & Beyond: Protocols & sequences in Node - Part 1
Bahul Neel Upadhyaya
 
PDF
tokyotalk
Hiroshi Ono
 
PDF
Reversing the dropbox client on windows
extremecoders
 
PPTX
Python with a SWIG of c++
bobmcn
 
PPTX
GopherCon Denver LT 2018
Prateek Gogia
 
PDF
Free Monads Getting Started
Kent Ohashi
 
PDF
Music as data
John Vlachoyiannis
 
TXT
Script
fauzasmg
 
PDF
Faster Python, FOSDEM
Victor Stinner
 
Go concurrency
siuyin
 
Golang design4concurrency
Eduardo Ferro Aldama
 
Happy Go Programming Part 1
Lin Yo-An
 
Concurrency with Go
Frank Müller
 
Implementing Software Machines in Go and C
Eleanor McHugh
 
Let's golang
SuHyun Jeon
 
Go Language Hands-on Workshop Material
Romin Irani
 
Clojure+ClojureScript Webapps
Falko Riemenschneider
 
Defer, Panic, Recover
Joris Bonnefoy
 
Introduction to go language programming
Mahmoud Masih Tehrani
 
Hands on Session on Python
Sumit Raj
 
To Infinity & Beyond: Protocols & sequences in Node - Part 1
Bahul Neel Upadhyaya
 
tokyotalk
Hiroshi Ono
 
Reversing the dropbox client on windows
extremecoders
 
Python with a SWIG of c++
bobmcn
 
GopherCon Denver LT 2018
Prateek Gogia
 
Free Monads Getting Started
Kent Ohashi
 
Music as data
John Vlachoyiannis
 
Script
fauzasmg
 
Faster Python, FOSDEM
Victor Stinner
 

Viewers also liked (6)

PDF
Math1003 1.12 - Binary Addition
gcmath1003
 
PDF
Binary addition
Martin Jacob
 
PPTX
Binary arithmetic
Elizabeth de Leon Aler
 
PPT
binary arithmetic rules
student
 
PPT
Binary Arithmetic
gavhays
 
PPTX
WTF - Why the Future Is Up to Us - pptx version
Tim O'Reilly
 
Math1003 1.12 - Binary Addition
gcmath1003
 
Binary addition
Martin Jacob
 
Binary arithmetic
Elizabeth de Leon Aler
 
binary arithmetic rules
student
 
Binary Arithmetic
gavhays
 
WTF - Why the Future Is Up to Us - pptx version
Tim O'Reilly
 
Ad

Similar to Coding in GO - GDG SL - NSBM (20)

PPTX
Golang
Fatih Şimşek
 
PPT
Introduction to Go ProgrammingLanguage.ppt
PedroAlexandre215482
 
PPTX
Golang - Overview of Go (golang) Language
Aniruddha Chakrabarti
 
PDF
Go lang
Suelen Carvalho
 
PDF
LCA2014 - Introduction to Go
dreamwidth
 
PDF
Go language presentation
paramisoft
 
PPTX
The GO Language : From Beginners to Gophers
I.I.S. G. Vallauri - Fossano
 
PDF
Golang
Saray Chak
 
PDF
Golang and Eco-System Introduction / Overview
Markus Schneider
 
PPTX
go language- haseeb.pptx
ArsalanMaqsood1
 
PDF
Inroduction to golang
Yoni Davidson
 
PPTX
Should i Go there
Shimi Bandiel
 
PDF
Lecture 1 - Overview of Go Language 1.pdf
daomaithuhuyen1273
 
PDF
Introduction to Go programming language
Slawomir Dorzak
 
PPT
Go1
vivekraj3434
 
PPTX
Go Programming language, golang
Basil N G
 
PDF
golang_refcard.pdf
Spam92
 
PPTX
Go Programming Language (Golang)
Ishin Vin
 
PDF
Introduction to Programming in Go
Amr Hassan
 
Introduction to Go ProgrammingLanguage.ppt
PedroAlexandre215482
 
Golang - Overview of Go (golang) Language
Aniruddha Chakrabarti
 
LCA2014 - Introduction to Go
dreamwidth
 
Go language presentation
paramisoft
 
The GO Language : From Beginners to Gophers
I.I.S. G. Vallauri - Fossano
 
Golang
Saray Chak
 
Golang and Eco-System Introduction / Overview
Markus Schneider
 
go language- haseeb.pptx
ArsalanMaqsood1
 
Inroduction to golang
Yoni Davidson
 
Should i Go there
Shimi Bandiel
 
Lecture 1 - Overview of Go Language 1.pdf
daomaithuhuyen1273
 
Introduction to Go programming language
Slawomir Dorzak
 
Go Programming language, golang
Basil N G
 
golang_refcard.pdf
Spam92
 
Go Programming Language (Golang)
Ishin Vin
 
Introduction to Programming in Go
Amr Hassan
 
Ad

Recently uploaded (20)

PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 

Coding in GO - GDG SL - NSBM

  • 1. coding in GO Monthly meetup November 2015 NSBM Raveen Perera
  • 2. History Created by Robert Griesemer, Rob Pike, Ken Thompson Developed in 2007 and first stable open source release 2009 (BSD) GO Fast, compiled language, directly to machine code and spearheaded by
  • 3. What’s so special about GO ? Compilation Very fast compilation (seconds) No VM needed GOs Assembler Tools go fmt go vet go test go doc Concurrency Asynchronous processes called GOroutines Channels used to pass data between routines Standard Library net/http flag encoding/json encoding/xml Simplicity in Syntax GO stands between C and Python Highly influenced by many other popular programming languages Deployment Can be compiled to a single binary file You can build and compile in your host or server
  • 5. Download and install GO https://golang.org/dl/ Download and install Sublime Text 3 http://www.sublimetext.com/3 and install GOSublime plugin https://github.com/DisposaBoy/GoSublime
  • 6. package main import ( "fmt" ) func main() { fmt.Println("Hello World!") } $ go run helloworld.go
  • 7. The Basics https://golang.org/ref/spec Variables var age int = 40 name := “John Doe” const pi float64 = 3.14 strings “ ” or ` ` bool true false + - * / % && || ! == != >= <=
  • 8. Loops for i := 0; i < count; i++ { } for i, value := range array { } for i <= 10 { i++ }
  • 9. Conditions if i > 10 { } else if i > 5 { } else { } switch grade { case 75: fmt.Println("A") default: fmt.Println("nothing") }
  • 10. Arrays var myArray[5] int myArray := [5]int {1,2,3,4,5} mySlice := []int {1,2,3,4,5} //Slice has no size declaration mySlice2 := mySlice[3:5] slice := make([]int, 5, 10) slice = append(slice,0,1)
  • 11. Maps Just like dictionaries in python grades := make(map[string] int) grades[“John”] = 80 delete(grades,”John”)
  • 12. Functions func myFunc(number int) int { return number + 5 } func myFunc(number int) (int,int) { return number + 5, number +6 } Executes after the enclosing function defer myFunc() Undefined number of variables func uParams(args ...int) int { }
  • 13. func divide(num1 int, num2 int) int { defer func() { fmt.Println(recover()) }() answer := num1/ num2 return answer } func divide() { defer func() { fmt.Println(recover()) }() panic(“sending to recover”) } Functions - defer() and panic()
  • 14. Closure Declaring a function inside another func main() { myfunc := func() int {} myfunc() }
  • 15. Pointers x := 8 changeX(&x) func changeX(x *int){ *x = 10 } myPointer := new(int) X memory address (0xc0820022b0)
  • 16. Structures Go is not object oriented type Circle struct { var radius float64 var name string } myCircle = Circle{name:”circle1” , radius:5} func (circle Circle) area() float64 { return circle.radius*circle.radius*3.14 }
  • 17. Handling Concurrency GORoutines Not expensive as threads Multiple Goroutines without cost Channels GORoutines reads and writes values from an to channels to communicate https://golang.org/pkg/sync/atomic/
  • 18. GO http Route Handles the requests and determines which function should handle that request Handler The function that executes when a request is made Server The networking code which handles the requests and routes (Serve mux) multiplexer, http request router
  • 19. Simple http server Simple respond writer package main import "net/http" func main() { http.HandleFunc("/", homeHandler) http.ListenAndServe(":8100", nil) } func homeHandler(w http.ResponseWriter, r *http.Request) { w.Write([]byte("අ◌ායුෙබ◌ා◌් වන්")) }
  • 20. Gorilla Toolkit Gorilla Mux $ go get github.com/gorilla/mux simple buffer writer Gorilla sessions $ go get github.com/gorilla/sessions
  • 21. GO Frameworks Toolkits and Micro Frameworks https://github.com/golang/go/wiki/LearnServerProgramming
  • 23. Thank You Monthly meetup November 2015 NSBM Raveen Perera