SlideShare uma empresa 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

Mais conteúdo relacionado

Semelhante 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
 

Semelhante 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
 

Mais 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

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Go nuts with Go and PHP

Notas do 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