SlideShare a Scribd company logo
1 of 54
Download to read offline
GO and REACT
CODELAB
Conduct
https://developers.google.com/programs/c
ommunity/gdg/resources/
Facts about You
Build a Go and React APP
@aljesusg
Picking up Go
Why 01
Code
Install
Sample & Run
Build
Conclusion
02
03
04
05
06
WHY
01
Go is a modern,
general purpose
language.
01. BACKGROUND
WHAT IS GO?
02
Compiles to native
machine code
(32-bit and 64-bit
x86, ARM).
WHAT IS GO?
01. BACKGROUND
03
Lightweight syntax.
WHAT IS GO?
01. BACKGROUND
Debugging is twice as hard as writing the
code in the first place. Therefore, if you
write the code as cleverly as possible,
you are, by definition, not smart enough
to debug it.
BRIAN KERNIGHAN
ROB PIKE
Go's purpose is to
make its designers'
programming lives
better.
Go’s Values
01. WHY
● Thoughtful
● Simple
● Efficient
● Reliable
● Productive
● Friendly
Go ROCKS
01. WHY
● Docker
● Juju
● Dropbox
● Google
● MercadoLibre
● MongoDB
● Netflix
● SoundCloud
● Uber
Go Guide
01. WHY
https://tour.golang.org/
TYPES & METHODS
02. CODE
type Abser interface {
Abs() float64
}
Interfaces specify behaviors.
An interface type defines a set
of methods:
Types implement interfaces implicitly. There is no “implements” declaration.
func PrintAbs(a Abser) {
fmt.Printf("Absolute value:
%.2fn", a.Abs())
}
PrintAbs(MyFloat(-10))
PrintAbs(Point{3, 4})
A type that implements those
methods implements the
interface:
Setup
03. INSTALL
● https://golang.org/doc/install
● Install
○ Linux, Mac OS X, and FreeBSD tarballs
■ tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
■ export PATH=$PATH:/usr/local/go/bin
Hello GDGGranada
04. SAMPLE & RUN
package main
import “fmt”
func main() {
fmt.Printf(“hello, gdgn”)
}
Make dir src/hello in your
workspace, and create file
named hello.go
cd $HOME/go/src/hello
go run hello.go
Hello GDGGranada
04. BUILD
env GOOS=target-OS GOARCH=target-architecture go build
env GOOS=windows GOARCH=386 go build
go build
How many OS and Arch?
OS & ARCH
04. BUILD
CONCLUSION
05. CONCLUSION
https://benchmarksgame.alioth.debian.org/u64
q/compare.php?lang=go&lang2=python3
Ready Backend
Backend API
Use a router
go get github.com/gorilla/mux
Ready Backend
Backend API
import (
"log"
"net/http"
"fmt"
"github.com/gorilla/mux"
)
func main() {
fmt.Println("Hello,gdgn")
router := mux.NewRouter()
log.Fatal(http.ListenAndServe(":8000", router))
}
Ready Backend
Backend API
import (
"log"
"net/http"
"fmt"
"github.com/gorilla/mux"
)
func main() {
fmt.Println("Hello,gdgn")
router := mux.NewRouter()
router.HandleFunc("<url>", <function>).Methods(<method>)
log.Fatal(http.ListenAndServe(":8000", router))
}
Ready Backend
Backend API
func <name>(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("OK"))
}
Ready Backend
Backend API
type Etsiitiano struct {
Name string
Hobbies []string
}
func <name>(w http.ResponseWriter, r *http.Request) {
etsiitian := Etsiitiano{"Alex", []string{"snowboarding",
"programming"}}
js, err := json.Marshal(etsiitian)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(js)
}
Ready Backend
Backend API
func <name>(w http.ResponseWriter, r *http.Request) {
etsiitian := Etsiitiano{"Alex", []string{"snowboarding",
"programming"}}
x, err := xml.MarshalIndent(etsiitian, "", " ")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/xml")
w.Write(x)
}
Ready Backend
Backend API
func <name>(w http.ResponseWriter, r *http.Request) {
etsiitian := Etsiitiano{"Alex", []string{"snowboarding", "programming"}}
if r.Header.Get("Type") == "xml"{
result, err := xml.MarshalIndent(etsiitian, "", " ")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/xml")
w.Write(result)
}else{
result, err := json.Marshal(etsiitian)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(result)
}
}
Ready Backend
Backend API
func GetOutput(result interface{}, w http.ResponseWriter, r *http.Request){
if r.Header.Get("Type") == "xml"{
response, err := xml.MarshalIndent(result, "", " ")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/xml")
log.Print("Returned in XMl format")
w.Write(response)
}else{
response, err := json.Marshal(result)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
log.Print("Returned in JSON format")
w.Header().Set("Content-Type", "application/json")
w.Write(response)
}
}
Ready Backend
Backend API
func GetOutput(result interface{}, w http.ResponseWriter, typ string){
w.Header().Set("Content-Type", "application/" + typ)
log.Print("Returned in " + typ + " format")
var response []byte;
var err error;
switch typ {
case "xml":
response, err = xml.MarshalIndent(result, "", " ")
case "json":
response, err = json.Marshal(result)
default:
log.Print("Error no type " + typ)
return
}
if err != nil {
log.Fatal("Error in marshal")
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Write(response)
}
Ready Backend
Backend API
Students
Ready Backend
Backend API
type Etsiitiano struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Hobbies []string `json:"hobbies,omitempty"`
Address Address `json:"address,omitempty"`
}
type Address struct {
City string `json:"city,omitempty"`
State string `json:"state,omitempty"`
}
Ready Backend
Backend API
func GetStudents(w http.ResponseWriter, r *http.Request) {
GetOutput(students, w, r.Header.Get("Type"))
}
Ready Backend
Backend API
func GetStudent(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
for _, item := range students {
if item.ID == params["id"] {
GetOutput(item, w, r.Header.Get("Type"))
return
}
}
GetOutput(&Etsiitiano{}, w, r.Header.Get("Type"))
}
Ready Backend
Backend API
func CreateStudent(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
var person Etsiitiano
error := json.NewDecoder(r.Body).Decode(&person)
if error != nil{
log.Fatal(error)
}
person.ID = params["id"]
students = append(students, person)
GetOutput(students, w, r.Header.Get("Type"))
}
Ready Backend
Backend API
func DeleteStudent(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
for index, item := range students {
if item.ID == params["id"] {
students = append(students[:index], students[index+1:]...)
break
}
GetOutput(students, w, r.Header.Get("Type"))
}
}
Ready Backend
Backend API
curl -X GET localhost:8000/students -H "type: json"
curl -X POST localhost:8000/student/3 -H "type: json" -d '{"name":"Alberto"}'
curl -X DELETE localhost:8000/student/3 -H "type: json"
Ready Backend
Backend API
curl -X GET localhost:8000/students -H "type: json"
curl -X POST localhost:8000/student/3 -H "type: json" -d '{"name":"Alberto"}'
curl -X DELETE localhost:8000/student/3 -H "type: json"
REACT TIME
npx create-react-app my-app
yarn build
fileServerHandler := http.FileServer(http.Dir("my-app/build"))
router.PathPrefix("/").Handler(fileServerHandler)
npm install --save react react-dom
npm install --save react-bootstrap
Rock Boostrap
npm install --save axios
npm install --save axios
"proxy": "http://localhost:8000/",
constructor(props) {
super(props);
this.fetchServiceDetails()
}
fetchServiceDetails() {
axios({
method: 'GET',
url: '/students',
headers: {'type':'json'}
})
.then(response => {
let data = response['data'];
console.log(data)
})
.catch(error => {
console.log(error)
});
};
{this.state.students && (
<table>
<thead>
<tr><td>Name</td></tr>
</thead>
<tbody>
{ this.state.students.map( stu => (
<tr><td>{stu.name}</td></tr>
))}
</tbody>
</table>
)}
TRY TO DO REFRESH STUDENTS
TRY TO DO DELETE STUDENT
EXPERIENCES
REAL APP
Don't be shy about asking
Don't be shy about asking
“Don't be shy about asking for
help when you need it”
Go react codelab

More Related Content

What's hot

Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
MongoDB
 

What's hot (20)

Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the AST
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 
All things that are not code
All things that are not codeAll things that are not code
All things that are not code
 
Reactive, component 그리고 angular2
Reactive, component 그리고  angular2Reactive, component 그리고  angular2
Reactive, component 그리고 angular2
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
 
Rails on Oracle 2011
Rails on Oracle 2011Rails on Oracle 2011
Rails on Oracle 2011
 
Node js mongodriver
Node js mongodriverNode js mongodriver
Node js mongodriver
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
Net/http and the http.handler interface
Net/http and the http.handler interfaceNet/http and the http.handler interface
Net/http and the http.handler interface
 
JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
 
GoCracow #5 Bartlomiej klimczak - GoBDD
GoCracow #5 Bartlomiej klimczak - GoBDDGoCracow #5 Bartlomiej klimczak - GoBDD
GoCracow #5 Bartlomiej klimczak - GoBDD
 
The Snake and the Butler
The Snake and the ButlerThe Snake and the Butler
The Snake and the Butler
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
Why Every Tester Should Learn Ruby
Why Every Tester Should Learn RubyWhy Every Tester Should Learn Ruby
Why Every Tester Should Learn Ruby
 
JavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# Developers
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
 
greenDAO
greenDAOgreenDAO
greenDAO
 
Minimizing Decision Fatigue to Improve Team Productivity
Minimizing Decision Fatigue to Improve Team ProductivityMinimizing Decision Fatigue to Improve Team Productivity
Minimizing Decision Fatigue to Improve Team Productivity
 

Similar to Go react codelab

Golang slidesaudrey
Golang slidesaudreyGolang slidesaudrey
Golang slidesaudrey
Audrey Lim
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
Sven Haiges
 
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Matteo Collina
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
偉格 高
 

Similar to Go react codelab (20)

Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
Golang slidesaudrey
Golang slidesaudreyGolang slidesaudrey
Golang slidesaudrey
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
Angular Restmod (english version)
Angular Restmod (english version)Angular Restmod (english version)
Angular Restmod (english version)
 
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and OperationsNeo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and Operations
 
Nodejsexplained 101116115055-phpapp02
Nodejsexplained 101116115055-phpapp02Nodejsexplained 101116115055-phpapp02
Nodejsexplained 101116115055-phpapp02
 
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...
 
GraphTour - Utilizing Powerful Extensions for Analytics & Operations
GraphTour - Utilizing Powerful Extensions for Analytics & OperationsGraphTour - Utilizing Powerful Extensions for Analytics & Operations
GraphTour - Utilizing Powerful Extensions for Analytics & Operations
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and Operations
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platforms
 
Net/http and the http.handler interface
Net/http and the http.handler interfaceNet/http and the http.handler interface
Net/http and the http.handler interface
 
huhu
huhuhuhu
huhu
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App Engine
 
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey BuzdinMarvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005
 
Android dev toolbox
Android dev toolboxAndroid dev toolbox
Android dev toolbox
 
jSession #4 - Maciej Puchalski - Zaawansowany retrofit
jSession #4 - Maciej Puchalski - Zaawansowany retrofitjSession #4 - Maciej Puchalski - Zaawansowany retrofit
jSession #4 - Maciej Puchalski - Zaawansowany retrofit
 

Recently uploaded

Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 

Recently uploaded (20)

Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 

Go react codelab