SlideShare a Scribd company logo
Submit Search
Upload
Desenvolvendo APIs em Go usando Middlewares
Report
Share
Elton Minetto
Software developer, teacher, speaker, open source evangelist, tech leader at Code:Nation
Follow
•
2 likes
•
950 views
1
of
17
Desenvolvendo APIs em Go usando Middlewares
•
2 likes
•
950 views
Report
Share
Download Now
Download to read offline
Technology
Como usar o conceito de Middlewares em Go
Read more
Elton Minetto
Software developer, teacher, speaker, open source evangelist, tech leader at Code:Nation
Follow
Recommended
PSR-7, middlewares e o futuro dos frameworks by
PSR-7, middlewares e o futuro dos frameworks
Elton Minetto
3.4K views
•
38 slides
Codeigniter : Two Step View - Concept Implementation by
Codeigniter : Two Step View - Concept Implementation
Abdul Malik Ikhsan
4.2K views
•
13 slides
Php server variables by
Php server variables
JIGAR MAKHIJA
379 views
•
5 slides
Cakephpstudy5 hacks by
Cakephpstudy5 hacks
Hiroki Shimizu
535 views
•
31 slides
Symfony 2.0 on PHP 5.3 by
Symfony 2.0 on PHP 5.3
Fabien Potencier
3.5K views
•
118 slides
Extending the WordPress REST API - Josh Pollock by
Extending the WordPress REST API - Josh Pollock
Caldera Labs
4.9K views
•
30 slides
More Related Content
What's hot
APPlause - DemoCamp Munich by
APPlause - DemoCamp Munich
Peter Friese
964 views
•
24 slides
Twib in Yokoahma.pm 2010/3/5 by
Twib in Yokoahma.pm 2010/3/5
Yusuke Wada
1.7K views
•
17 slides
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 - by
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
Yusuke Wada
3K views
•
56 slides
Silex Cheat Sheet by
Silex Cheat Sheet
Andréia Bohner
4K views
•
17 slides
Zero to SOLID by
Zero to SOLID
Vic Metcalfe
943 views
•
84 slides
Mojolicious by
Mojolicious
Marcos Rebelo
5.4K views
•
44 slides
What's hot
(20)
APPlause - DemoCamp Munich by Peter Friese
APPlause - DemoCamp Munich
Peter Friese
•
964 views
Twib in Yokoahma.pm 2010/3/5 by Yusuke Wada
Twib in Yokoahma.pm 2010/3/5
Yusuke Wada
•
1.7K views
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 - by Yusuke Wada
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
Yusuke Wada
•
3K views
Silex Cheat Sheet by Andréia Bohner
Silex Cheat Sheet
Andréia Bohner
•
4K views
Zero to SOLID by Vic Metcalfe
Zero to SOLID
Vic Metcalfe
•
943 views
Mojolicious by Marcos Rebelo
Mojolicious
Marcos Rebelo
•
5.4K views
Mojolicious by Lenz Gschwendtner
Mojolicious
Lenz Gschwendtner
•
963 views
Sadi service by Mark Wilkinson
Sadi service
Mark Wilkinson
•
297 views
Example code for the SADI BMI Calculator Web Service by Mark Wilkinson
Example code for the SADI BMI Calculator Web Service
Mark Wilkinson
•
884 views
Алексей Плеханов: Новинки Laravel 5 by Oleg Poludnenko
Алексей Плеханов: Новинки Laravel 5
Oleg Poludnenko
•
1.5K views
Blog Hacks 2011 by Yusuke Wada
Blog Hacks 2011
Yusuke Wada
•
2.7K views
TDC2015 Porto Alegre - Automate everything with Phing ! by Matheus Marabesi
TDC2015 Porto Alegre - Automate everything with Phing !
Matheus Marabesi
•
1K views
Psr 7 symfony-day by Marco Perone
Psr 7 symfony-day
Marco Perone
•
658 views
Build REST API clients for AngularJS by Almog Baku
Build REST API clients for AngularJS
Almog Baku
•
3.6K views
4.2 PHP Function by Jalpesh Vasa
4.2 PHP Function
Jalpesh Vasa
•
1.4K views
Complex Sites with Silex by Chris Tankersley
Complex Sites with Silex
Chris Tankersley
•
2.8K views
YAPC::Asia 2010 Twitter解析サービス by Yusuke Wada
YAPC::Asia 2010 Twitter解析サービス
Yusuke Wada
•
1.8K views
Building Modern and Secure PHP Applications – Codementor Office Hours with Be... by Arc & Codementor
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Arc & Codementor
•
11.2K views
Getting Started-with-Laravel by Mindfire Solutions
Getting Started-with-Laravel
Mindfire Solutions
•
2.2K views
Class 6 - PHP Web Programming by Ahmed Swilam
Class 6 - PHP Web Programming
Ahmed Swilam
•
1.8K views
Viewers also liked
Do monolito ao micro serviço by
Do monolito ao micro serviço
Elton Minetto
848 views
•
26 slides
Metodologias ágeis interativas by
Metodologias ágeis interativas
Elton Minetto
1.6K views
•
88 slides
Leveraging a distributed architecture to your advantage by
Leveraging a distributed architecture to your advantage
Michelangelo van Dam
1.5K views
•
66 slides
E-commerce e o novo consumidor by
E-commerce e o novo consumidor
Elton Minetto
684 views
•
36 slides
Inovação e tecnologia by
Inovação e tecnologia
Elton Minetto
505 views
•
35 slides
Code Squad by
Code Squad
Elton Minetto
754 views
•
12 slides
Viewers also liked
(13)
Do monolito ao micro serviço by Elton Minetto
Do monolito ao micro serviço
Elton Minetto
•
848 views
Metodologias ágeis interativas by Elton Minetto
Metodologias ágeis interativas
Elton Minetto
•
1.6K views
Leveraging a distributed architecture to your advantage by Michelangelo van Dam
Leveraging a distributed architecture to your advantage
Michelangelo van Dam
•
1.5K views
E-commerce e o novo consumidor by Elton Minetto
E-commerce e o novo consumidor
Elton Minetto
•
684 views
Inovação e tecnologia by Elton Minetto
Inovação e tecnologia
Elton Minetto
•
505 views
Code Squad by Elton Minetto
Code Squad
Elton Minetto
•
754 views
De Padawan a Jedi - Versão 2016 by Elton Minetto
De Padawan a Jedi - Versão 2016
Elton Minetto
•
627 views
Ao infinito e além com PHP memcached e Gearman by Elton Minetto
Ao infinito e além com PHP memcached e Gearman
Elton Minetto
•
4K views
DevOps e PHP by Elton Minetto
DevOps e PHP
Elton Minetto
•
3.1K views
PHP like a super hero by Elton Minetto
PHP like a super hero
Elton Minetto
•
740 views
PHP para Adultos: Clean Code e Object Calisthenics by Guilherme Blanco
PHP para Adultos: Clean Code e Object Calisthenics
Guilherme Blanco
•
17.2K views
You code sucks, let's fix it by Rafael Dohms
You code sucks, let's fix it
Rafael Dohms
•
56.4K views
Otimização MySQL by Elton Minetto
Otimização MySQL
Elton Minetto
•
2.9K views
Similar to Desenvolvendo APIs em Go usando Middlewares
Intro to Node by
Intro to Node
Aaron Stannard
5.2K views
•
25 slides
Angular 4 The new Http Client Module by
Angular 4 The new Http Client Module
arjun singh
1.2K views
•
19 slides
Net/http and the http.handler interface by
Net/http and the http.handler interface
Joakim Gustin
75 views
•
42 slides
Net/http and the http.handler interface by
Net/http and the http.handler interface
Evolve
266 views
•
42 slides
RESTEasy by
RESTEasy
Massimiliano Dessì
1.7K views
•
37 slides
May 2010 - RestEasy by
May 2010 - RestEasy
JBug Italy
1.3K views
•
37 slides
Similar to Desenvolvendo APIs em Go usando Middlewares
(20)
Intro to Node by Aaron Stannard
Intro to Node
Aaron Stannard
•
5.2K views
Angular 4 The new Http Client Module by arjun singh
Angular 4 The new Http Client Module
arjun singh
•
1.2K views
Net/http and the http.handler interface by Joakim Gustin
Net/http and the http.handler interface
Joakim Gustin
•
75 views
Net/http and the http.handler interface by Evolve
Net/http and the http.handler interface
Evolve
•
266 views
RESTEasy by Massimiliano Dessì
RESTEasy
Massimiliano Dessì
•
1.7K views
May 2010 - RestEasy by JBug Italy
May 2010 - RestEasy
JBug Italy
•
1.3K views
Clojure and the Web by nickmbailey
Clojure and the Web
nickmbailey
•
1.9K views
Java web programming by Ching Yi Chan
Java web programming
Ching Yi Chan
•
4.3K views
Sun RPC (Remote Procedure Call) by Peter R. Egli
Sun RPC (Remote Procedure Call)
Peter R. Egli
•
13.3K views
Customising Your Own Web Framework In Go by Jonathan Gomez
Customising Your Own Web Framework In Go
Jonathan Gomez
•
1.3K views
Web Server.pdf by Bareen Shaikh
Web Server.pdf
Bareen Shaikh
•
20 views
Ruby HTTP clients comparison by Hiroshi Nakamura
Ruby HTTP clients comparison
Hiroshi Nakamura
•
26.3K views
Web by googli
Web
googli
•
473 views
Introduction to web and php mysql by Programmer Blog
Introduction to web and php mysql
Programmer Blog
•
476 views
RESTing with JAX-RS by Ezewuzie Emmanuel Okafor
RESTing with JAX-RS
Ezewuzie Emmanuel Okafor
•
636 views
Exploring Async PHP (SF Live Berlin 2019) by dantleech
Exploring Async PHP (SF Live Berlin 2019)
dantleech
•
483 views
Java Servlets by BG Java EE Course
Java Servlets
BG Java EE Course
•
31K views
Job Managment Portlet by riround
Job Managment Portlet
riround
•
610 views
Intoduction to Play Framework by Knoldus Inc.
Intoduction to Play Framework
Knoldus Inc.
•
2.2K views
T2 by Mo Ch
T2
Mo Ch
•
348 views
More from Elton Minetto
Go e Microserviços - Nascidos um para o outro by
Go e Microserviços - Nascidos um para o outro
Elton Minetto
1.9K views
•
37 slides
Object Calisthenics em Go by
Object Calisthenics em Go
Elton Minetto
792 views
•
79 slides
Programar != desenvolver software (v2) by
Programar != desenvolver software (v2)
Elton Minetto
341 views
•
22 slides
Gerenciando uma startup no Github Projects by
Gerenciando uma startup no Github Projects
Elton Minetto
402 views
•
30 slides
Clean Architecture by
Clean Architecture
Elton Minetto
912 views
•
37 slides
Serverless em Go by
Serverless em Go
Elton Minetto
428 views
•
31 slides
More from Elton Minetto
(20)
Go e Microserviços - Nascidos um para o outro by Elton Minetto
Go e Microserviços - Nascidos um para o outro
Elton Minetto
•
1.9K views
Object Calisthenics em Go by Elton Minetto
Object Calisthenics em Go
Elton Minetto
•
792 views
Programar != desenvolver software (v2) by Elton Minetto
Programar != desenvolver software (v2)
Elton Minetto
•
341 views
Gerenciando uma startup no Github Projects by Elton Minetto
Gerenciando uma startup no Github Projects
Elton Minetto
•
402 views
Clean Architecture by Elton Minetto
Clean Architecture
Elton Minetto
•
912 views
Serverless em Go by Elton Minetto
Serverless em Go
Elton Minetto
•
428 views
JAMstack by Elton Minetto
JAMstack
Elton Minetto
•
517 views
Clean architecture em Go - v2 by Elton Minetto
Clean architecture em Go - v2
Elton Minetto
•
652 views
Programar != desenvolver software by Elton Minetto
Programar != desenvolver software
Elton Minetto
•
1.6K views
Clean Architecture em PHP by Elton Minetto
Clean Architecture em PHP
Elton Minetto
•
3.3K views
Clean Architecture in Golang by Elton Minetto
Clean Architecture in Golang
Elton Minetto
•
1.4K views
A jornada do desenvolvedor by Elton Minetto
A jornada do desenvolvedor
Elton Minetto
•
636 views
Product and Technology by Elton Minetto
Product and Technology
Elton Minetto
•
542 views
Code:Nation Tech Stack by Elton Minetto
Code:Nation Tech Stack
Elton Minetto
•
476 views
Modernizando projetos legados usando APIs by Elton Minetto
Modernizando projetos legados usando APIs
Elton Minetto
•
1K views
12 factor in the PHP world by Elton Minetto
12 factor in the PHP world
Elton Minetto
•
1.4K views
Building APIs using Go by Elton Minetto
Building APIs using Go
Elton Minetto
•
1K views
Start you by Elton Minetto
Start you
Elton Minetto
•
311 views
O case da Compufácil e AWS by Elton Minetto
O case da Compufácil e AWS
Elton Minetto
•
256 views
Introdução a Go by Elton Minetto
Introdução a Go
Elton Minetto
•
1.2K views
Recently uploaded
Kyo - Functional Scala 2023.pdf by
Kyo - Functional Scala 2023.pdf
Flavio W. Brasil
368 views
•
92 slides
PRODUCT LISTING.pptx by
PRODUCT LISTING.pptx
angelicacueva6
14 views
•
1 slide
Vertical User Stories by
Vertical User Stories
Moisés Armani Ramírez
14 views
•
16 slides
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
IttrainingIttraining
52 views
•
8 slides
20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf
Phactum Softwareentwicklung GmbH
41 views
•
73 slides
Case Study Copenhagen Energy and Business Central.pdf by
Case Study Copenhagen Energy and Business Central.pdf
Aitana
16 views
•
3 slides
Recently uploaded
(20)
Kyo - Functional Scala 2023.pdf by Flavio W. Brasil
Kyo - Functional Scala 2023.pdf
Flavio W. Brasil
•
368 views
PRODUCT LISTING.pptx by angelicacueva6
PRODUCT LISTING.pptx
angelicacueva6
•
14 views
Vertical User Stories by Moisés Armani Ramírez
Vertical User Stories
Moisés Armani Ramírez
•
14 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
IttrainingIttraining
•
52 views
20231123_Camunda Meetup Vienna.pdf by Phactum Softwareentwicklung GmbH
20231123_Camunda Meetup Vienna.pdf
Phactum Softwareentwicklung GmbH
•
41 views
Case Study Copenhagen Energy and Business Central.pdf by Aitana
Case Study Copenhagen Energy and Business Central.pdf
Aitana
•
16 views
Future of Indian ConsumerTech by Kapil Khandelwal (KK)
Future of Indian ConsumerTech
Kapil Khandelwal (KK)
•
21 views
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial Services
Precisely
•
21 views
AMAZON PRODUCT RESEARCH.pdf by JerikkLaureta
AMAZON PRODUCT RESEARCH.pdf
JerikkLaureta
•
26 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdf
madhurjyapb
•
14 views
Unit 1_Lecture 2_Physical Design of IoT.pdf by StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec
•
12 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
Jasper Oosterveld
•
18 views
Zero to Automated in Under a Year by Network Automation Forum
Zero to Automated in Under a Year
Network Automation Forum
•
15 views
HTTP headers that make your website go faster - devs.gent November 2023 by Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn
•
22 views
PRODUCT PRESENTATION.pptx by angelicacueva6
PRODUCT PRESENTATION.pptx
angelicacueva6
•
14 views
METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ... by Prity Khastgir IPR Strategic India Patent Attorney Amplify Innovation
METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ...
Prity Khastgir IPR Strategic India Patent Attorney Amplify Innovation
•
29 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson
•
85 views
Mini-Track: Challenges to Network Automation Adoption by Network Automation Forum
Mini-Track: Challenges to Network Automation Adoption
Network Automation Forum
•
12 views
Network Source of Truth and Infrastructure as Code revisited by Network Automation Forum
Network Source of Truth and Infrastructure as Code revisited
Network Automation Forum
•
26 views
Democratising digital commerce in India-Report by Kapil Khandelwal (KK)
Democratising digital commerce in India-Report
Kapil Khandelwal (KK)
•
15 views
Desenvolvendo APIs em Go usando Middlewares
1.
Desenvolvendo APIs usando middlewares Elton Minetto @eminetto http://eltonminetto.net http://asemanago.com.br elton@planrockr.com
2.
Http Is The
Foundation Of The Web
3.
Um cliente manda
uma request r.Method - HTTP method (GET, POST, PUT, PATCH, DELETE etc.) r.URL.Path - Request path (/things/123) r.URL.String() - Full URL r.URL.Query() - Query parameters (q=something&p=2) r.Body - io.ReadCloser of the request body
4.
O servidor retorna
uma response type ResponseWriter interface { Header() Header Write([]byte) (int, error) WriteHeader(int) }
5.
Middlewares
6.
Between the request
and response Enrico Zimuel HTTP middleware is not for your Domain work. The middleware is a path in to, and out of, the core Domain. Paul M. Jones Run code before and after handler code Mat Ryer
8.
Exemplos
9.
func middlewareOne(next http.Handler)
http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { log.Println("Executing before middlewareOne") next.ServeHTTP(w, r) log.Println("Executing after middlewareOne") }) }
10.
func middlewareTwo(next http.Handler)
http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { log.Println("Executing before middlewareTwo") if r.URL.Path != "/" { return } next.ServeHTTP(w, r) log.Println("Executing after middlewareTwo") }) } func final(w http.ResponseWriter, r *http.Request) { log.Println("Executing finalHandler") w.Write([]byte("OK")) }
11.
func main() { finalHandler
:= http.HandlerFunc(final) http.Handle("/", middlewareOne(middlewareTwo(finalHandler))) http.ListenAndServe(":8000", nil) }
12.
https://github.com/justinas/alice
13.
func main() { finalHandler
:= http.HandlerFunc(final) chain := alice.New(middlewareOne, middlewareTwo).Then(finalHandler) http.ListenAndServe(":8000", chain) }
14.
package main import ( "github.com/justinas/alice" "net/http" "planrockr" ) func
getCurrentSubscription(w http.ResponseWriter, r *http.Request) { ... } func main() { chain := alice.New(planrockr.Auth, planrockr.GetUserByToken). Then(http.HandlerFunc(getCurrentSubscription)) http.ListenAndServe(":8000", chain) }
15.
package main import ( "github.com/justinas/alice" "net/http" "planrockr" ) func
processEvent(next http.Handler) http.Handler { ... } func main() { chain := alice.New(processEvent, planrockr.ValidateHookData). Then(http.HandlerFunc(planrockr.Enqueue)) http.ListenAndServe(":8000", chain) }
16.
Links https://gist.github.com/eminetto/ e3bab34426ac9a0b83a538a0e421bbc8
17.
Contato @eminetto http://eltonminetto.net http://asemanago.com.br elton@planrockr.com