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

PDF
Introduction to go
PDF
Go serving: Building server app with go
PDF
Golang concurrency design
PDF
Cotap Tech Talks: Keith Lazuka, Digital Communication using Sound and Swift
PDF
Geeks Anonymes - Le langage Go
PDF
PDF
Concurrency in Golang
KEY
GoLightly: A Go Library For Building Virtual Machines
Introduction to go
Go serving: Building server app with go
Golang concurrency design
Cotap Tech Talks: Keith Lazuka, Digital Communication using Sound and Swift
Geeks Anonymes - Le langage Go
Concurrency in Golang
GoLightly: A Go Library For Building Virtual Machines

What's hot (20)

PDF
Go concurrency
PDF
Golang design4concurrency
PDF
Happy Go Programming Part 1
PDF
Concurrency with Go
PDF
Implementing Software Machines in Go and C
PDF
Let's golang
PPTX
Go Language Hands-on Workshop Material
PDF
Clojure+ClojureScript Webapps
PDF
Defer, Panic, Recover
PDF
Introduction to go language programming
ODP
Hands on Session on Python
ODP
To Infinity & Beyond: Protocols & sequences in Node - Part 1
PDF
tokyotalk
PDF
Reversing the dropbox client on windows
PPTX
Python with a SWIG of c++
PPTX
GopherCon Denver LT 2018
PDF
Free Monads Getting Started
PDF
Music as data
TXT
Script
PDF
Faster Python, FOSDEM
Go concurrency
Golang design4concurrency
Happy Go Programming Part 1
Concurrency with Go
Implementing Software Machines in Go and C
Let's golang
Go Language Hands-on Workshop Material
Clojure+ClojureScript Webapps
Defer, Panic, Recover
Introduction to go language programming
Hands on Session on Python
To Infinity & Beyond: Protocols & sequences in Node - Part 1
tokyotalk
Reversing the dropbox client on windows
Python with a SWIG of c++
GopherCon Denver LT 2018
Free Monads Getting Started
Music as data
Script
Faster Python, FOSDEM
Ad

Viewers also liked (6)

PDF
Math1003 1.12 - Binary Addition
PDF
Binary addition
PPTX
Binary arithmetic
PPT
binary arithmetic rules
PPT
Binary Arithmetic
PPTX
WTF - Why the Future Is Up to Us - pptx version
Math1003 1.12 - Binary Addition
Binary addition
Binary arithmetic
binary arithmetic rules
Binary Arithmetic
WTF - Why the Future Is Up to Us - pptx version
Ad

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

PPTX
Golang basics for Java developers - Part 1
PDF
Trivadis TechEvent 2016 Go - The Cloud Programming Language by Andija Sisko
PPTX
The GO Language : From Beginners to Gophers
PDF
Golang
PPTX
golang_getting_started.pptx
PDF
Go for Rubyists
PDF
Let's Go-lang
PPT
Introduction to Go ProgrammingLanguage.ppt
PPT
Python ppt
PDF
Go 1.10 Release Party - PDX Go
PDF
Introduction to Python Programming | InsideAIML
PDF
Introduction to Programming in Go
PDF
Golang workshop
PPTX
Iron Languages - NYC CodeCamp 2/19/2011
PDF
Inroduction to golang
PDF
Golang勉強会
PPTX
Golang iran - tutorial go programming language - Preliminary
PPTX
Introduction to Python Programming
PPTX
Introduction to F#
Golang basics for Java developers - Part 1
Trivadis TechEvent 2016 Go - The Cloud Programming Language by Andija Sisko
The GO Language : From Beginners to Gophers
Golang
golang_getting_started.pptx
Go for Rubyists
Let's Go-lang
Introduction to Go ProgrammingLanguage.ppt
Python ppt
Go 1.10 Release Party - PDX Go
Introduction to Python Programming | InsideAIML
Introduction to Programming in Go
Golang workshop
Iron Languages - NYC CodeCamp 2/19/2011
Inroduction to golang
Golang勉強会
Golang iran - tutorial go programming language - Preliminary
Introduction to Python Programming
Introduction to F#

Recently uploaded (20)

PPTX
Cell Types and Its function , kingdom of life
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Pharma ospi slides which help in ospi learning
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
RMMM.pdf make it easy to upload and study
Cell Types and Its function , kingdom of life
Final Presentation General Medicine 03-08-2024.pptx
PPH.pptx obstetrics and gynecology in nursing
102 student loan defaulters named and shamed – Is someone you know on the list?
Pharma ospi slides which help in ospi learning
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Week 4 Term 3 Study Techniques revisited.pptx
human mycosis Human fungal infections are called human mycosis..pptx
VCE English Exam - Section C Student Revision Booklet
2.FourierTransform-ShortQuestionswithAnswers.pdf
Microbial disease of the cardiovascular and lymphatic systems
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Cell Structure & Organelles in detailed.
01-Introduction-to-Information-Management.pdf
Institutional Correction lecture only . . .
Microbial diseases, their pathogenesis and prophylaxis
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
RMMM.pdf make it easy to upload and study

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