SlideShare una empresa de Scribd logo
1 de 29
GO NUTS WITH 
GO
and PHP

@mgiglesia
About me
●

Love to be here!
–

●

●

Ouro Preto!

Miramar, Argentina
I code a lot (C++, Node.js, PHP, Python, Java, 
Go, Ruby)

●

PHP community

●

Workana
IT'S ALL ABOUT
Interoperability
Other languages
PHP programmers
IT'S ALL ABOUT
Interoperability
APIs
API centric design
User API
PHP

Payments 
Java
API

Fraud API
Python

Notifications 
Go
API

Emails API
REST
Ok. So GO.
Why?
Google had issues. Yes it did.
●

Compilation / building time

●

Endless dependencies (#ifndef)

●

Concurrency

●

Garbage collection

●

Cross­compilation

●

Strict types

●

Performance (duh!)
Isn't it constantly changing?
$ go fix app.go
What can I use it for?
●

In WORKANA:
–

URL shortener → 
https://github.com/mariano/goshorty

–

Real time notification system

–

High performance tracking

–

Map Reduce
Olá Mundo
package main
import "fmt"
func main() {
fmt.Println("Olá Brasil!")
}

$ go fmt hello_world.go
$ go build hello_world.go
$ ./hello_world
Packages
$ go get github.com/garyburd/redigo/redis
import (
"github.com/garyburd/redigo/redis"
"time"
)
redis.Pool{
MaxIdle: 5,
IdleTimeout: 240 * time.Second,
Dial: func () (redis.Conn, error) {
c, err := redis.Dial("tcp", "localhost")
if err != nil {
return nil, err
}
return c, nil
},
}
Object oriented... really?
●

There are no concept of classes

●

No inheritance (duh!)

●

Everything is about composition
No classes?
const roleAdmin = "admin";
type People {

Public

Email string
Registered time.Time
role string

}

Private

func (p *People) IsAdmin() bool {
return (p.role == roleAdmin)
}
Sort of like 
$this
No classes?
type User interface {
IsAdmin() bool

}
func printUser(u User) {
fmt.Println("Is Admin:", u.IsAdmin())

}
u := &People{
Email: "test@email.com",
role: roleAdmin,

}
printUser(u)
Instead of inheritance, composition
type Person interface {
Name() string

}
type User struct {
Person
Email string

}
type RegisteredUser struct {
Person
Name string

}
func (u *User) Name() string {
return u.Email

}
func (r *RegisteredUser) Name() string {
return u.name

}
u := &User{
Email: "test@email.com",

}
r := &RegisteredUser{
name: "Mariano",

}
fmt.Println(u.Name(), r.Name()

Sort of like traits
Functions

Multiple values

func do(a int64, b int64) (x int64, y float64) {
x = a * b
y = float64(a / b)
return
Named return

}
Closure

func main() {
g := func(n int64) (int64, float64) {
return do(n, 10)

}
fmt.Println(g(50))

}
Errors vs. Exceptions
func Connect(host string) (Connection, error) {
// ….
}

c, err := Connect("localhost")
if err != nil {
panic(err)

}
Defers
func log(m string) error {
f, err := file.Open("/tmp/debug.log")
if err != nil {
return err

}
defer f.Close()
f.WriteString(m)

}
Goroutines
func main() {
go func() {
for {
if !worker.Work() {
break
}

}

}()
fmt.Println("Waiting...")
time.Sleep(5 * time.Second)

}

Not very nice. What can we
do to know goroutine is done
Channels
func main() {
finished := make(chan bool)
go func() {
defer close(finished)
for {
if !worker.Work() {
finished <- true
break
}

}

}()
<-finished

}
Select in channels
pings := make(chan int)
go func() {
i := 0
for {
pings <- i
i++
time.Sleep(time.Second)

}

}()
Select in channels
messages := make(chan string)
go func() {
i := 0
for {
messages <- fmt.Sprintf("Message #%d", i)
i++
time.Sleep(time.Second * 3)

}

}()
Select in channels
go func() {
for {
select {
case m := <- messages:
fmt.Println("[MESSAGE]", m)
case p := <- pings:
fmt.Println("[PING]", p)

}

}

}()
<- time.After(time.Second * 10)
Some Tips
Think memory and performance!
m := make(map[string]map[string]string)
a := make(map[string]string)
a["key1"] = "value1"
a["key2"] = "value2"
m["settings"] = a
a2 := &Settings{
key1: "value1",
key2: "value2",
}
m2 := &Data{
settings: a2,
}
Web framework?
●

Gorilla
–

mux: router / dispatcher

–

sessions: diferentes stores (filesystem / cookies)

–

schema: from POST to struct

●

martini

●

web.go

●

revel
Questions?

@mgiglesia

Más contenido relacionado

Similar a Go nuts with Go and PHP

Random tips that will save your project's life
Random tips that will save your project's lifeRandom tips that will save your project's life
Random tips that will save your project's life
Mariano Iglesias
 
Php4android TDC 2011
Php4android TDC 2011Php4android TDC 2011
Php4android TDC 2011
Kinn Julião
 
Introduction To Apache Pig at WHUG
Introduction To Apache Pig at WHUGIntroduction To Apache Pig at WHUG
Introduction To Apache Pig at WHUG
Adam Kawa
 

Similar a Go nuts with Go and PHP (20)

Random tips that will save your project's life
Random tips that will save your project's lifeRandom tips that will save your project's life
Random tips that will save your project's life
 
IPC 2013 - High Performance PHP with HipHop
IPC 2013 - High Performance PHP with HipHopIPC 2013 - High Performance PHP with HipHop
IPC 2013 - High Performance PHP with HipHop
 
PHP, Under The Hood - DPC
PHP, Under The Hood - DPCPHP, Under The Hood - DPC
PHP, Under The Hood - DPC
 
Laravel level 0 (introduction)
Laravel level 0 (introduction)Laravel level 0 (introduction)
Laravel level 0 (introduction)
 
PUG ROMAGNA - Alternative a Magento2
PUG ROMAGNA - Alternative a Magento2PUG ROMAGNA - Alternative a Magento2
PUG ROMAGNA - Alternative a Magento2
 
Write in Go
Write in GoWrite in Go
Write in Go
 
Intro to GO (Bangkok Launchpad 2014)
Intro to GO (Bangkok Launchpad 2014)Intro to GO (Bangkok Launchpad 2014)
Intro to GO (Bangkok Launchpad 2014)
 
Python in real world.
Python in real world.Python in real world.
Python in real world.
 
Go lang
Go langGo lang
Go lang
 
Php4android TDC 2011
Php4android TDC 2011Php4android TDC 2011
Php4android TDC 2011
 
Joomla REST API
Joomla REST APIJoomla REST API
Joomla REST API
 
Go fundamentals
Go fundamentalsGo fundamentals
Go fundamentals
 
Go, meet Lua
Go, meet LuaGo, meet Lua
Go, meet Lua
 
go language- haseeb.pptx
go language- haseeb.pptxgo language- haseeb.pptx
go language- haseeb.pptx
 
Golang
GolangGolang
Golang
 
Java Freelancing
Java FreelancingJava Freelancing
Java Freelancing
 
Go/Ruby/Java: What's next?
Go/Ruby/Java: What's next?Go/Ruby/Java: What's next?
Go/Ruby/Java: What's next?
 
Golang nuts (by Nii Nai at DevCongress 2013)
Golang nuts (by Nii Nai at DevCongress 2013)Golang nuts (by Nii Nai at DevCongress 2013)
Golang nuts (by Nii Nai at DevCongress 2013)
 
Introduction To Apache Pig at WHUG
Introduction To Apache Pig at WHUGIntroduction To Apache Pig at WHUG
Introduction To Apache Pig at WHUG
 
Phonegap - Girl Geek Sydney
Phonegap - Girl Geek SydneyPhonegap - Girl Geek Sydney
Phonegap - Girl Geek Sydney
 

Más de Mariano Iglesias (7)

ElasticSearch: la tenés atroden Google
ElasticSearch: la tenés atroden GoogleElasticSearch: la tenés atroden Google
ElasticSearch: la tenés atroden Google
 
Workana: work in your underwear and still get paid
Workana: work in your underwear and still get paidWorkana: work in your underwear and still get paid
Workana: work in your underwear and still get paid
 
node-db: La excusa perfecta para hablar de C++ y Node.js
node-db: La excusa perfecta para hablar de C++ y Node.jsnode-db: La excusa perfecta para hablar de C++ y Node.js
node-db: La excusa perfecta para hablar de C++ y Node.js
 
ONGs como Extreme Startups
ONGs como Extreme StartupsONGs como Extreme Startups
ONGs como Extreme Startups
 
Node.js - Eventos para Todos
Node.js - Eventos para TodosNode.js - Eventos para Todos
Node.js - Eventos para Todos
 
Things that suck... and some that don't
Things that suck... and some that don'tThings that suck... and some that don't
Things that suck... and some that don't
 
Going crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPGoing crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHP
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 

Go nuts with Go and PHP

Notas del editor

  1. * Map reduce: el master divide el problema en problemas mas chicos, se los da a workers. (Mapeo). Luego el worker devuelve el resultado, el master collecciona los resultados de sus workers, y genera su resultado (Reduce)
  2. * La rutina se ejecuta en un threadpool. Dependiendo del compilador (gccgo, etc) puede ser un thread por routine, o no