SlideShare a Scribd company logo
LET'S GO-LANG 
Luka Zakrajšek 
CTO @ Koofr 
@bancek 
First Ljubljana Go Meetup 
December 8, 2014
WHAT IS GO 
new programming language from Google 
low level 
C-like syntax 
fast compilation (for large codebases) 
compiles to single library 
cross platform (Windows, Linux, Mac)
WHAT IS GO 
statically-typed 
managed memory (garbage collection) 
type safety 
dynamic-typing capabilities 
built-in types (variable-length arrays and key-value maps) 
large standard library
GO IS C 
#include <stdio.h> 
main() 
{ 
printf("Hello Worldn"); 
return 0; 
} 
package main 
import "fmt" 
func main() { 
fmt.Println("Hello World") 
}
GO IS PYTHON 
import re 
import os 
import Image 
import csv 
import json 
import gzip 
import urllib 
import unittest 
import ( 
"regexp" 
"os.exec" 
"image/jpeg" 
"encoding/csv" 
"encoding/json" 
"compress/gzip" 
"net/http" 
"testing" 
) 
import "github.com/koofr/go-koofrclient"
GO IS NODE.JS 
var http = require('http'); 
http.createServer(function (req, res) { 
res.writeHead(200); 
res.end('Hello World'); 
}).listen(1337, '127.0.0.1'); 
console.log('Server running at http://127.0.0.1:1337/'); 
package main 
import ( 
"fmt" 
"net/http" 
) func main() { 
http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) { 
fmt.Fprintf(w, "Hello World") 
}) 
http.ListenAndServe(":1337", nil) 
fmt.Println("Server running at http://127.0.0.1:1337/"); 
}
BASIC CONSTRUCTS
PACKAGES 
libraries structured in packages 
programs start running in package main
IMPORTS 
local imports (GOPATH env. variable) 
import directly from web (http, git, mercurial) 
capitalized identifiers are exported 
import ( 
"fmt" 
"github.com/koofr/go-koofrclient" 
)
FUNCTIONS 
take zero or more arguments 
a function can return any number of results. 
types come after variable names 
named return values 
func myfunction(x, y int) (x int, y int) { 
tmp := x 
x = y 
y = tmp 
return 
// return y, x 
}
VARIABLES 
var statement declares a list of variables 
type comes after name 
var c, python, java bool 
func main() { 
var i int 
fmt.Println(i, c, python, java) 
} 
short variable declarations 
func main() { 
var i int = 1 
k := 3 // type inference 
}
BASIC TYPES 
bool 
string 
int, uint, int8, uint, int16, uint16, int32, uint32, int64, uint64, 
uintptr 
byte // alias for uint8 
rune // alias for int32, represents a Unicode code point 
float32, float64 
complex64, complex128
OTHER CONSTRUCTS 
pointers 
structs 
arrays 
slices 
maps
INTERFACES 
type Reader interface { 
Read(p []byte) (n int, err error) 
}
INTERFACES 
type SizeReader struct { 
r io.Reader 
size int64 
} func (sr *SizeReader) Read(p []byte) (n int, err error) { 
n, err = sr.r.Read(p) 
sr.size += int64(n) 
return 
} func consumeReader(r io.Reader) { 
// ... 
} func main() { 
var sr *SizeReader = &SizeReader{myFile, 0} 
consumeReader(sr) 
fmt.Println(sr.size) 
}
GOROUTINES AND CHANNELS 
func doSomethingExpensive() int { 
time.Sleep(10 * time.Second) 
return 42 
} 
func doItAsync() { 
go doSomethingExpensive() 
} 
func doItAsyncAndGetResult() <-chan int { 
ch := make(chan int, 1) 
go func() { 
ch <- doSomethingExpensive() 
}() 
return ch 
}
ERROR HANDLING 
func copyFile(src string, dest string) (i64, error) { 
r, err := os.Open(src) 
if err != nil { 
return err 
} 
defer r.Close() 
w, err := os.Create(dest) 
if err != nil { 
return err 
} 
defer w.Close() 
bytesCopied, err = io.Copy(w, r) 
return bytesCopied, err 
}
GO COMMAND 
// fetch dependencies 
go get 
// run tests 
go test 
// build binary 
go build 
// format code 
go fmt 
// check for errors in code 
go vet
CODE STRUCTURE
LIBRARY STRUCTURE 
.gitignore 
LICENSE 
README.md 
cache.go 
cache_test.go
APPLICATION STRUCTURE 
src/ 
github.com/ 
koofr/ 
go-ioutils 
myapp/ 
internallib/ 
lib.go 
main/ 
main.go 
config.go 
myapp.go 
bin/ 
myapp 
pkg/ 
build/ 
dist/
TESTING 
package newmath 
import "testing" 
func TestSqrt(t *testing.T) { 
const in, out = 4, 2 
if x := Sqrt(in); x != out { 
t.Errorf("Sqrt(%v) = %v, want %v", in, x, out) 
} 
} 
$ go test 
ok github.com/user/newmath 0.165s
DEPLOYMENT 
go build -o bin/myapp src/myapp/main/main.go 
scp bin/myapp myserver.com:myapp 
ssh myserver.com 'supervisorctl restart myapp'
GO @ KOOFR 
backend 
content server (downloads, uploads, streaming ...) 
FTP server 
... 
desktop application 
GUI application 
sync 
native places
QUESTIONS?

More Related Content

PDF
Go for Rubyists
Luka Zakrajšek
 
PDF
Emscripten, asm.js, and billions of math ops
Luka Zakrajšek
 
PPTX
Modern frontend in react.js
Abdulsattar Mohammed
 
PPTX
Introduction to .NET
Lorenzo Dematté
 
PDF
LLVM Workshop Osaka Umeda, Japan
ujihisa
 
PDF
Libtcc and gwan
DaeMyung Kang
 
PDF
Groovify your java code by hervé roussel
Hervé Vũ Roussel
 
Go for Rubyists
Luka Zakrajšek
 
Emscripten, asm.js, and billions of math ops
Luka Zakrajšek
 
Modern frontend in react.js
Abdulsattar Mohammed
 
Introduction to .NET
Lorenzo Dematté
 
LLVM Workshop Osaka Umeda, Japan
ujihisa
 
Libtcc and gwan
DaeMyung Kang
 
Groovify your java code by hervé roussel
Hervé Vũ Roussel
 

What's hot (20)

DOCX
Note
Posoffaith1
 
PDF
Clojure+ClojureScript Webapps
Falko Riemenschneider
 
PDF
Rcpp11 useR2014
Romain Francois
 
KEY
Python 3 - tutorial
Andrews Medina
 
PPT
Multithreading in PHP
dimitriyremerov
 
DOCX
Jose dossantos.doc
josedossantos0512
 
PPTX
C++ hello world
AL- AMIN
 
PDF
Full Stack Clojure
Michiel Borkent
 
PDF
ClojureScript loves React, DomCode May 26 2015
Michiel Borkent
 
PDF
ClojureScript for the web
Michiel Borkent
 
PDF
Gogo shell
jwausle
 
PDF
Live in shell
Tiến Nguyễn
 
TXT
Forkexpe
Karthic Rao
 
PDF
PyCon KR 2019 sprint - RustPython by example
YunWon Jeong
 
PPT
Loops (1)
esmail said
 
PDF
Bash Scripting
Vincent Claes
 
PDF
ClojureScript - A functional Lisp for the browser
Falko Riemenschneider
 
DOCX
RedHat/CentOs Commands for administrative works
Md Shihab
 
PDF
Node intro
cloudhead
 
Clojure+ClojureScript Webapps
Falko Riemenschneider
 
Rcpp11 useR2014
Romain Francois
 
Python 3 - tutorial
Andrews Medina
 
Multithreading in PHP
dimitriyremerov
 
Jose dossantos.doc
josedossantos0512
 
C++ hello world
AL- AMIN
 
Full Stack Clojure
Michiel Borkent
 
ClojureScript loves React, DomCode May 26 2015
Michiel Borkent
 
ClojureScript for the web
Michiel Borkent
 
Gogo shell
jwausle
 
Live in shell
Tiến Nguyễn
 
Forkexpe
Karthic Rao
 
PyCon KR 2019 sprint - RustPython by example
YunWon Jeong
 
Loops (1)
esmail said
 
Bash Scripting
Vincent Claes
 
ClojureScript - A functional Lisp for the browser
Falko Riemenschneider
 
RedHat/CentOs Commands for administrative works
Md Shihab
 
Node intro
cloudhead
 
Ad

Viewers also liked (15)

PPTX
Golang iran - tutorial go programming language - Preliminary
go-lang
 
PPTX
Microservices in GO lang
SHAKIL AKHTAR
 
PPT
App using golang indicthreads
IndicThreads
 
PPT
Go Programming Language - Learning The Go Lang way
IndicThreads
 
PPT
Introduction to Go-Lang
Folio3 Software
 
PPTX
EuroPython 2016 - Do I Need To Switch To Golang
Max Tepkeev
 
PDF
Go lang
Suelen Carvalho
 
PPT
Google Go! language
André Mayer
 
PDF
Golang
Felipe Mamud
 
PDF
Introduction au langage Go
Sylvain Wallez
 
PPTX
Golang
Michael Blake
 
PDF
10 reasons to be excited about go
Dvir Volk
 
PDF
AddisDev Meetup ii: Golang and Flow-based Programming
Samuel Lampa
 
PDF
An introduction to go programming language
Technology Parser
 
PDF
Go Lang migrating billions of documents
Jônatas Paganini
 
Golang iran - tutorial go programming language - Preliminary
go-lang
 
Microservices in GO lang
SHAKIL AKHTAR
 
App using golang indicthreads
IndicThreads
 
Go Programming Language - Learning The Go Lang way
IndicThreads
 
Introduction to Go-Lang
Folio3 Software
 
EuroPython 2016 - Do I Need To Switch To Golang
Max Tepkeev
 
Google Go! language
André Mayer
 
Golang
Felipe Mamud
 
Introduction au langage Go
Sylvain Wallez
 
10 reasons to be excited about go
Dvir Volk
 
AddisDev Meetup ii: Golang and Flow-based Programming
Samuel Lampa
 
An introduction to go programming language
Technology Parser
 
Go Lang migrating billions of documents
Jônatas Paganini
 
Ad

Similar to Let's Go-lang (20)

PDF
Inroduction to golang
Yoni Davidson
 
PDF
Go serving: Building server app with go
Hean Hong Leong
 
PDF
Golang and Eco-System Introduction / Overview
Markus Schneider
 
PPTX
The GO Language : From Beginners to Gophers
I.I.S. G. Vallauri - Fossano
 
PDF
LCA2014 - Introduction to Go
dreamwidth
 
PPTX
Go Programming Language (Golang)
Ishin Vin
 
PDF
Go, the one language to learn in 2014
Andrzej Grzesik
 
PDF
JDD2014: GO! The one language you have to try in 2014 - Andrzej Grzesik
PROIDEA
 
PPTX
Go. Why it goes
Sergey Pichkurov
 
PDF
Introduction to Go programming language
Slawomir Dorzak
 
PDF
Golang workshop
Victor S. Recio
 
PPTX
Golang - Overview of Go (golang) Language
Aniruddha Chakrabarti
 
PDF
golang_refcard.pdf
Spam92
 
PDF
Go Java, Go!
Andres Almiray
 
PDF
Introduction to Programming in Go
Amr Hassan
 
PPTX
Go Java, Go!
Andres Almiray
 
PPTX
Golang basics for Java developers - Part 1
Robert Stern
 
PDF
Geeks Anonymes - Le langage Go
Geeks Anonymes
 
PPTX
golang_getting_started.pptx
Guy Komari
 
PDF
Go Lang Tutorial
Wei-Ning Huang
 
Inroduction to golang
Yoni Davidson
 
Go serving: Building server app with go
Hean Hong Leong
 
Golang and Eco-System Introduction / Overview
Markus Schneider
 
The GO Language : From Beginners to Gophers
I.I.S. G. Vallauri - Fossano
 
LCA2014 - Introduction to Go
dreamwidth
 
Go Programming Language (Golang)
Ishin Vin
 
Go, the one language to learn in 2014
Andrzej Grzesik
 
JDD2014: GO! The one language you have to try in 2014 - Andrzej Grzesik
PROIDEA
 
Go. Why it goes
Sergey Pichkurov
 
Introduction to Go programming language
Slawomir Dorzak
 
Golang workshop
Victor S. Recio
 
Golang - Overview of Go (golang) Language
Aniruddha Chakrabarti
 
golang_refcard.pdf
Spam92
 
Go Java, Go!
Andres Almiray
 
Introduction to Programming in Go
Amr Hassan
 
Go Java, Go!
Andres Almiray
 
Golang basics for Java developers - Part 1
Robert Stern
 
Geeks Anonymes - Le langage Go
Geeks Anonymes
 
golang_getting_started.pptx
Guy Komari
 
Go Lang Tutorial
Wei-Ning Huang
 

Recently uploaded (20)

PDF
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PDF
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
PDF
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
PPTX
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PPT
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
PDF
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
PDF
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PPTX
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
DOCX
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
Presentation about variables and constant.pptx
safalsingh810
 
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Can You Build Dashboards Using Open Source Visualization Tool.docx
Varsha Nayak
 
Exploring AI Agents in Process Industries
amoreira6
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 

Let's Go-lang

  • 1. LET'S GO-LANG Luka Zakrajšek CTO @ Koofr @bancek First Ljubljana Go Meetup December 8, 2014
  • 2. WHAT IS GO new programming language from Google low level C-like syntax fast compilation (for large codebases) compiles to single library cross platform (Windows, Linux, Mac)
  • 3. WHAT IS GO statically-typed managed memory (garbage collection) type safety dynamic-typing capabilities built-in types (variable-length arrays and key-value maps) large standard library
  • 4. GO IS C #include <stdio.h> main() { printf("Hello Worldn"); return 0; } package main import "fmt" func main() { fmt.Println("Hello World") }
  • 5. GO IS PYTHON import re import os import Image import csv import json import gzip import urllib import unittest import ( "regexp" "os.exec" "image/jpeg" "encoding/csv" "encoding/json" "compress/gzip" "net/http" "testing" ) import "github.com/koofr/go-koofrclient"
  • 6. GO IS NODE.JS var http = require('http'); http.createServer(function (req, res) { res.writeHead(200); res.end('Hello World'); }).listen(1337, '127.0.0.1'); console.log('Server running at http://127.0.0.1:1337/'); package main import ( "fmt" "net/http" ) func main() { http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello World") }) http.ListenAndServe(":1337", nil) fmt.Println("Server running at http://127.0.0.1:1337/"); }
  • 8. PACKAGES libraries structured in packages programs start running in package main
  • 9. IMPORTS local imports (GOPATH env. variable) import directly from web (http, git, mercurial) capitalized identifiers are exported import ( "fmt" "github.com/koofr/go-koofrclient" )
  • 10. FUNCTIONS take zero or more arguments a function can return any number of results. types come after variable names named return values func myfunction(x, y int) (x int, y int) { tmp := x x = y y = tmp return // return y, x }
  • 11. VARIABLES var statement declares a list of variables type comes after name var c, python, java bool func main() { var i int fmt.Println(i, c, python, java) } short variable declarations func main() { var i int = 1 k := 3 // type inference }
  • 12. BASIC TYPES bool string int, uint, int8, uint, int16, uint16, int32, uint32, int64, uint64, uintptr byte // alias for uint8 rune // alias for int32, represents a Unicode code point float32, float64 complex64, complex128
  • 13. OTHER CONSTRUCTS pointers structs arrays slices maps
  • 14. INTERFACES type Reader interface { Read(p []byte) (n int, err error) }
  • 15. INTERFACES type SizeReader struct { r io.Reader size int64 } func (sr *SizeReader) Read(p []byte) (n int, err error) { n, err = sr.r.Read(p) sr.size += int64(n) return } func consumeReader(r io.Reader) { // ... } func main() { var sr *SizeReader = &SizeReader{myFile, 0} consumeReader(sr) fmt.Println(sr.size) }
  • 16. GOROUTINES AND CHANNELS func doSomethingExpensive() int { time.Sleep(10 * time.Second) return 42 } func doItAsync() { go doSomethingExpensive() } func doItAsyncAndGetResult() <-chan int { ch := make(chan int, 1) go func() { ch <- doSomethingExpensive() }() return ch }
  • 17. ERROR HANDLING func copyFile(src string, dest string) (i64, error) { r, err := os.Open(src) if err != nil { return err } defer r.Close() w, err := os.Create(dest) if err != nil { return err } defer w.Close() bytesCopied, err = io.Copy(w, r) return bytesCopied, err }
  • 18. GO COMMAND // fetch dependencies go get // run tests go test // build binary go build // format code go fmt // check for errors in code go vet
  • 20. LIBRARY STRUCTURE .gitignore LICENSE README.md cache.go cache_test.go
  • 21. APPLICATION STRUCTURE src/ github.com/ koofr/ go-ioutils myapp/ internallib/ lib.go main/ main.go config.go myapp.go bin/ myapp pkg/ build/ dist/
  • 22. TESTING package newmath import "testing" func TestSqrt(t *testing.T) { const in, out = 4, 2 if x := Sqrt(in); x != out { t.Errorf("Sqrt(%v) = %v, want %v", in, x, out) } } $ go test ok github.com/user/newmath 0.165s
  • 23. DEPLOYMENT go build -o bin/myapp src/myapp/main/main.go scp bin/myapp myserver.com:myapp ssh myserver.com 'supervisorctl restart myapp'
  • 24. GO @ KOOFR backend content server (downloads, uploads, streaming ...) FTP server ... desktop application GUI application sync native places