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 lifeMariano Iglesias
 
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 HipHopSteve Kamerman
 
PHP, Under The Hood - DPC
PHP, Under The Hood - DPCPHP, Under The Hood - DPC
PHP, Under The Hood - DPCAnthony Ferrara
 
PUG ROMAGNA - Alternative a Magento2
PUG ROMAGNA - Alternative a Magento2PUG ROMAGNA - Alternative a Magento2
PUG ROMAGNA - Alternative a Magento2Giuseppe Morelli
 
Intro to GO (Bangkok Launchpad 2014)
Intro to GO (Bangkok Launchpad 2014)Intro to GO (Bangkok Launchpad 2014)
Intro to GO (Bangkok Launchpad 2014)Matthew Campbell
 
Python in real world.
Python in real world.Python in real world.
Python in real world.Alph@.M
 
Php4android TDC 2011
Php4android TDC 2011Php4android TDC 2011
Php4android TDC 2011Kinn Julião
 
go language- haseeb.pptx
go language- haseeb.pptxgo language- haseeb.pptx
go language- haseeb.pptxArsalanMaqsood1
 
Go/Ruby/Java: What's next?
Go/Ruby/Java: What's next?Go/Ruby/Java: What's next?
Go/Ruby/Java: What's next?Hernan Wilkinson
 
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)DevCongress
 
Introduction To Apache Pig at WHUG
Introduction To Apache Pig at WHUGIntroduction To Apache Pig at WHUG
Introduction To Apache Pig at WHUGAdam Kawa
 
Phonegap - Girl Geek Sydney
Phonegap - Girl Geek SydneyPhonegap - Girl Geek Sydney
Phonegap - Girl Geek SydneyGeorgi Knox
 

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

ElasticSearch: la tenés atroden Google
ElasticSearch: la tenés atroden GoogleElasticSearch: la tenés atroden Google
ElasticSearch: la tenés atroden GoogleMariano Iglesias
 
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 paidMariano Iglesias
 
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.jsMariano Iglesias
 
ONGs como Extreme Startups
ONGs como Extreme StartupsONGs como Extreme Startups
ONGs como Extreme StartupsMariano Iglesias
 
Node.js - Eventos para Todos
Node.js - Eventos para TodosNode.js - Eventos para Todos
Node.js - Eventos para TodosMariano Iglesias
 
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'tMariano Iglesias
 
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 CakePHPMariano Iglesias
 

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

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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 educationjfdjdjcjdnsjd
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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 AmsterdamUiPathCommunity
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
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, ...Angeliki Cooney
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
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 ...apidays
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
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 Takeoffsammart93
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
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 challengesrafiqahmad00786416
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 

Último (20)

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
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, ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
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 ...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
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
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

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