SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Downloaden Sie, um offline zu lesen
GO FOR RUBYISTS?
Luka Zakrajšek
CTO @ Koofr
@bancek
Slovenia Ruby User Group, January Meetup
January 29, 2015
ABOUT ME
FRI graduate
CTO and cofounder at Koofr
Python developer in previous life
now mostly Scala, Go and JavaScript
GO @ KOOFR
Koofr is white-label cloud storage solution for ISPs
backend
content server (downloads, uploads, streaming ...)
FTP server
...
desktop application
GUI application
sync
remote filesystem access
WHAT IS GO
new programming language from Google
low level
C-like syntax
fast compilation (for large codebases)
compiles to single binary
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("HelloWorldn");
return0;
}
packagemain
import"fmt"
funcmain(){
fmt.Println("HelloWorld")
}
GO IS PYTHON
importre
importos
importImage
importcsv
importjson
importgzip
importurllib
importunittest
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
varhttp=require('http');
http.createServer(function(req,res){
res.writeHead(200);
res.end('HelloWorld');
}).listen(1337,'127.0.0.1');
console.log('Serverrunningathttp://127.0.0.1:1337/');
packagemain
import(
"fmt"
"net/http"
)
funcmain(){
http.HandleFunc("/",func(whttp.ResponseWriter,r*http.Request){
fmt.Fprintf(w,"HelloWorld")
})
http.ListenAndServe(":1337",nil)
fmt.Println("Serverrunningathttp://127.0.0.1:1337/");
}
GO FOR RUBYISTS
EASY AND CHEAP CONCURRENCY
easy to have dozens (or even thousands) of concurrent
operations
it will even take advantage of all the CPUs available
Ruby has threads, but there is GIL in Ruby MRI
Ruby has green threads, but will use single CPU
LOW MEMORY OVERHEAD
Go programs can be compiled to a few megabytes binary
memory efficient while harvesting the power of the entire
machine
EASY DEPLOYMENT
Go programs are compiled in a few seconds into small
executables
no dependencies in production
USE GO FROM RUBY
Go:
packagemain
import"fmt"
import"encoding/json"
funcmain(){
mapD:=map[string]int{"apple":5,"lettuce":7}
mapB,_:=json.Marshal(mapD)
fmt.Println(string(mapB))
}
Ruby:
JSON.parse(`gorunjson.go`)
#=>{"apple"=>5,"lettuce"=>7}
https://antoine.finkelstein.fr/go-in-ruby/
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
funcmyfunction(x,yint)(xint,yint){
tmp:=x
x=y
y=tmp
return
//returny,x
}
VARIABLES
var statement declares a list of variables
type comes after name
varc,python,javabool
funcmain(){
variint
fmt.Println(i,c,python,java)
}
short variable declarations
funcmain(){
variint=1
k:=3//typeinference
}
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
typeReaderinterface{
Read(p[]byte)(nint,errerror)
}
INTERFACES
typeSizeReaderstruct{
rio.Reader
sizeint64
}
func(sr*SizeReader)Read(p[]byte)(nint,errerror){
n,err=sr.r.Read(p)
sr.size+=int64(n)
return
}
funcconsumeReader(rio.Reader){
//...
}
funcmain(){
varsr*SizeReader=&SizeReader{myFile,0}
consumeReader(sr)
fmt.Println(sr.size)
}
GOROUTINES AND CHANNELS
funcdoSomethingExpensive()int{
time.Sleep(10*time.Second)
return42
}
funcdoItAsync(){
godoSomethingExpensive()
}
funcdoItAsyncAndGetResult()<-chanint{
ch:=make(chanint,1)
gofunc(){
ch<-doSomethingExpensive()
}()
returnch
}
ERROR HANDLING
funccopyFile(srcstring,deststring)(i64,error){
r,err:=os.Open(src)
iferr!=nil{
returnerr
}
deferr.Close()
w,err:=os.Create(dest)
iferr!=nil{
returnerr
}
deferw.Close()
bytesCopied,err=io.Copy(w,r)
returnbytesCopied,err
}
GO COMMAND
//fetchdependencies
goget
//runtests
gotest
//buildbinary
gobuild
//formatcode
gofmt
//checkforerrorsincode
govet
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
packagenewmath
import"testing"
funcTestSqrt(t*testing.T){
constin,out=4,2
ifx:=Sqrt(in);x!=out{
t.Errorf("Sqrt(%v)=%v,want%v",in,x,out)
}
}
$gotest
ok github.com/user/newmath0.165s
DEPLOYMENT
gobuild-obin/myappsrc/myapp/main/main.go
scpbin/myappmyserver.com:myapp
sshmyserver.com'supervisorctlrestartmyapp'
WEB FRAMEWORKS
MARTINI
Classy web framework for Go
similar to Sinatra
FEATURES
Flexible Routing
VeryflexibleandextremelyDRY.Nameparameters,stackhandlers,
injectthedependencies.
Comprehensive
Comeswithagreatsetofstockmiddleware:
Logging,Recovery,Staticfileserving,Authentication,Routingandmore!
Reuse Existing Code
FullycompatiblewithGo'shttp.HandlerFuncinterface.
LeveragethemanyawesomeopensourcewebpackagesbuiltinGo
MARTINI EXAMPLE
packagemain
import"github.com/go-martini/martini"
funcmain(){
m:=martini.Classic()
m.Get("/",func()string{
return"Helloworld!"
})
m.Get("/hello/:name",func(paramsmartini.Params)string{
return"Hello"+params["name"]
})
m.Run()
}
REVEL
A high-productivity web framework for the Go language.
similar to Rails
FEATURES
Hot Code Reload
Edit,save,andrefresh.
Comprehensive
routing,parameterparsing,validation,session/flash,
templating,caching,jobrunning,atestingframework,internationalization...
High Performance
BuiltontopoftheGoHTTPserver,threetotentimesasmanyrequestsasRails
FRAMEWORK DESIGN
Synchronous
TheGoHTTPserverrunseachrequestinitsowngoroutine.
Writesimplecallback-freecodewithoutguilt.
Stateless
Providesprimitivesthatkeepthewebtierstatelessforpredictablescaling.
Sessiondatainstoredcookies,cachebackedbyamemcachedcluster.
Modular
Composablemiddlewarecalledfilters,whichimplementnearlyall
request-processingfunctionality
REVEL PROJECT STRUCTURE
myapp Approot
app Appsources
controllers Appcontrollers
init.go Interceptorregistration
models Appdomainmodels
routes Reverseroutes(generatedcode)
views Templates
tests Testsuites
conf Configurationfiles
app.conf Mainconfigurationfile
routes Routesdefinition
messages Messagefiles
public Publicassets
css CSSfiles
js Javascriptfiles
images Imagefiles
QUESTIONS?

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the web
 
Full Stack Clojure
Full Stack ClojureFull Stack Clojure
Full Stack Clojure
 
Libtcc and gwan
Libtcc and gwanLibtcc and gwan
Libtcc and gwan
 
Gogo shell
Gogo shellGogo shell
Gogo shell
 
Python 3 - tutorial
Python 3 - tutorialPython 3 - tutorial
Python 3 - tutorial
 
LLVM Workshop Osaka Umeda, Japan
LLVM Workshop Osaka Umeda, JapanLLVM Workshop Osaka Umeda, Japan
LLVM Workshop Osaka Umeda, Japan
 
Live in shell
Live in shellLive in shell
Live in shell
 
Multithreading in PHP
Multithreading in PHPMultithreading in PHP
Multithreading in PHP
 
Groovify your java code by hervé roussel
Groovify your java code by hervé rousselGroovify your java code by hervé roussel
Groovify your java code by hervé roussel
 
Rcpp11 useR2014
Rcpp11 useR2014Rcpp11 useR2014
Rcpp11 useR2014
 
Jose dossantos.doc
Jose dossantos.docJose dossantos.doc
Jose dossantos.doc
 
Note
NoteNote
Note
 
C# Today and Tomorrow
C# Today and TomorrowC# Today and Tomorrow
C# Today and Tomorrow
 
Perl one-liners
Perl one-linersPerl one-liners
Perl one-liners
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
 
Linux containers
Linux containersLinux containers
Linux containers
 
PyCon KR 2019 sprint - RustPython by example
PyCon KR 2019 sprint  - RustPython by examplePyCon KR 2019 sprint  - RustPython by example
PyCon KR 2019 sprint - RustPython by example
 
Compiler basics: lisp to assembly
Compiler basics: lisp to assemblyCompiler basics: lisp to assembly
Compiler basics: lisp to assembly
 
Using zone.js
Using zone.jsUsing zone.js
Using zone.js
 
Make A Shoot ‘Em Up Game with Amethyst Framework
Make A Shoot ‘Em Up Game with Amethyst FrameworkMake A Shoot ‘Em Up Game with Amethyst Framework
Make A Shoot ‘Em Up Game with Amethyst Framework
 

Ähnlich wie Go for Rubyists

Ähnlich wie Go for Rubyists (20)

Coding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBMCoding in GO - GDG SL - NSBM
Coding in GO - GDG SL - NSBM
 
Code Deployment Evolution
Code Deployment EvolutionCode Deployment Evolution
Code Deployment Evolution
 
The Go features I can't live without, 2nd round
The Go features I can't live without, 2nd roundThe Go features I can't live without, 2nd round
The Go features I can't live without, 2nd round
 
Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1
 
Trivadis TechEvent 2016 Go - The Cloud Programming Language by Andija Sisko
Trivadis TechEvent 2016 Go - The Cloud Programming Language by Andija SiskoTrivadis TechEvent 2016 Go - The Cloud Programming Language by Andija Sisko
Trivadis TechEvent 2016 Go - The Cloud Programming Language by Andija Sisko
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microservice
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
 
An OpenShift Primer for Developers to get your Code into the Cloud (PTJUG)
An OpenShift Primer for Developers to get your Code into the Cloud (PTJUG)An OpenShift Primer for Developers to get your Code into the Cloud (PTJUG)
An OpenShift Primer for Developers to get your Code into the Cloud (PTJUG)
 
Debugging Python with gdb
Debugging Python with gdbDebugging Python with gdb
Debugging Python with gdb
 
Introduction to Google's Go programming language
Introduction to Google's Go programming languageIntroduction to Google's Go programming language
Introduction to Google's Go programming language
 
Physical Computing Using Go and Arduino
Physical Computing Using Go and ArduinoPhysical Computing Using Go and Arduino
Physical Computing Using Go and Arduino
 
Golang workshop
Golang workshopGolang workshop
Golang workshop
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 
Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3
 
Golang
GolangGolang
Golang
 
Introduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fastIntroduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fast
 
The GO Language : From Beginners to Gophers
The GO Language : From Beginners to GophersThe GO Language : From Beginners to Gophers
The GO Language : From Beginners to Gophers
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
 
PyQt Application Development On Maemo
PyQt Application Development On MaemoPyQt Application Development On Maemo
PyQt Application Development On Maemo
 
Import golang; struct microservice - Codemotion Rome 2015
Import golang; struct microservice - Codemotion Rome 2015Import golang; struct microservice - Codemotion Rome 2015
Import golang; struct microservice - Codemotion Rome 2015
 

Kürzlich hochgeladen

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Kürzlich hochgeladen (20)

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 

Go for Rubyists