SlideShare a Scribd company logo
Fast Web Applications
with Go
!

DevFestW Istanbul !
March 2,2014!
Ekin Eylem Ozekin!
Outline
!

² 

Introduction to Go!

² 

Web with Go!

² 

Is Go suitable to Web!

² 

Demo Web Application!

² 

Questions

!
But First of All, Me
!

• 

Ekin Eylem Ozekin!

• 

BSc. In Computer Science, MSc. In Software
Engineering!

• 

Currently, Ph.D. Candidate at Bogazici
University, on Machine Learning!

• 

Works at GE

!
Introduction to Go
!

• 

Built around 2007, announced at 2009!

• 

By “GO”ogle!

• 

Open Source!

• 

Similar to C!

• 

Statically typed, compiled!

• 

No pointer arithmetic

!
Introduction to Go
!

• 

Automatic memory management, classes
(structs), type inference!

• 

First class functions, suitable to functional
programming!

• 

Concurrency support, channels

!
Introduction to Go
!

• 

Ideal for fast, distributed systems!

• 

Can import libraries directly from URLs!

• 

Built-in UTF-8 support (İ, Ğ etc. works perfectly)!

• 

Integrated AppEngine libraries

!
Introduction to Go
!

package main!
!

import (!
"fmt"!
"net/http"!
)!
!

func get_name() (string, string) {!
// No reason to break a few rules, right!
var hello = "Hello "!
audience := "DevFestTR"!
return hello, audience!
}!
!
func handler(writer http.ResponseWriter, request *http.Request) {!
hello, audience := get_name()!
fmt.Fprintf(writer, hello + audience)!
}!
!
func main() {!
http.HandleFunc("/", handler)!
http.ListenAndServe(":8080", nil)!
}

!
Introduction to Go
!

• 

Written as read, left from right!

• 

No semicolons!

• 

Multiple return values (think of tuples in Python)!

• 

Single binary file after compile!

• 

More on the previous code later

!
Web with Go
!

• 

Built-in http package!

• 

Similar to J2EE Servlets!

• 

But more like a Micro-framework

!
Web with Go
!

• 

Web Development with the performance of C!

• 

Might be deployed with built-in server (port
listener actually)!

• 

Deploy to Apache or Nginx with FastCGI!

• 

Also mod_go for Apache!

• 

Deploy to AppEngine or Heroku

!
Is Go Suitable for Web
!

Should I use Go for Web?
!
Is Go Suitable for Web
!

Pros!

• 
• 

Micro-framework style http package!

• 

CGI support (kinda old but solid and useful)!

• 

Compiled, fast performance!

• 

C like Syntax but better!

• 

API is mature enough!
Is Go Suitable for Web
!

Cons!

• 
• 

Not easier then PHP (or Ruby or Python)!

• 

Not as widely used as others!

• 

Not proven enough yet (can be argued)!
Is Go Suitable for Web
!

Last Word!

• 
• 

Service Oriented Architecture and Micro Frameworks fit well!

• 

You don’t have to use just Go, use with others!

• 

Google already uses it (isn’t it enough reason?)!
Demo

!

A Web application with Go
!

!

Let’s GO!
Source Code
!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

Server Side Code!

package main!
import ("html/template"; "fmt"; "net/http"; "strconv")!
func main() {!
http.HandleFunc("/", form)!
http.HandleFunc("/show_age", form_handler)!
http.ListenAndServe(":8080", nil)!
}!
func form(writer http.ResponseWriter,!
request *http.Request) {!
genderList := []string { "Male", "Female" }!
t, _ := template.ParseFiles("form.html")!
t.Execute(writer, map[string]interface{} {!
"genders": genderList,!
"title": "DevFest Applicant Form",!
})!
}!
func form_handler(writer http.ResponseWriter,!
request *http.Request) {!
gender := request.FormValue("gender")!
message := ""!
if ("1" == gender) {!
message = "You don't ask a woman her age."!
} else {!
age, _ := strconv.Atoi(request.FormValue("age"))!
if (age < 1000) {!
message = "This boy is still alive and kicking"!
} else {!
message = ”Still too young!"!
} !
}!
fmt.Fprintf(writer, message)!
}

!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

Template Code!

<h1>{{.title}}</h1>!
<p>!
Fill in your gender and age.!
<br />!
And I will tell you if you are old or not...!
</p>!
<form action="/show_age" method="POST">!
<dl>!
<dt>Gender</dt>!
<dd>!
<select name="gender" style="width: 125px;">!
{{range $index, $value := .genders}}!
<option value="{{$index}}" />{{$value}}!
{{end}}!
</select>!
</dd>!
<dt>Age</dt>!
<dd><input type="text" name="age" /></dd>!
</dl>!
<input type="submit" value="Save">!
</form>

!
More information
!

² 

http://golang.org/doc/!

² 

http://golang.org/doc/articles/gos_declaration_syntax.html!

² 

http://blog.iron.io/2013/08/go-after-2-years-in-production.html!
Questions?

!

?

!

Thank you for listening!
!

Ekin Eylem Ozekin!
eeozekin@gmail.com

!
Q&A Session
!

• 
• 

• 
• 
• 
• 
• 
• 

Is there a Database Abstraction layer?!
As there are no classes ORM is a bit crippled. However, there are few implementations on that.
You can find those here: http://jmoiron.net/blog/golang-orms/ . There are also bindings for popular
databases: http://go-lang.cat-v.org/library-bindings!
What can I use for User Interfaces?!
There is a GTK binding for that. For more libraries you can check:
http://go-lang.cat-v.org/library-bindings!
To return multiple values Python returns actually a Tuple data structure. Is it similar in Go too?!
No. Go really returns multiple values.!
If I can something on a template, should I recompile in order to see changes?!
No, you don’t. If you make a change on the template code, all you have to do is refresh the page.
However you should be careful, when deploying to the server you should make sure that those
templates exist too.

!

More Related Content

PDF
Metaprogramming Go
PDF
Why use Go for web development?
PDF
Migrate PHP E-Commerce Site to Go
PPTX
Untangling - fall2017 - week 7
PPTX
How to Supercharge your PHP Web API
PPTX
Functional Programming in PHP
PDF
Python to go
PPTX
Untangling - fall2017 - week 9
Metaprogramming Go
Why use Go for web development?
Migrate PHP E-Commerce Site to Go
Untangling - fall2017 - week 7
How to Supercharge your PHP Web API
Functional Programming in PHP
Python to go
Untangling - fall2017 - week 9

What's hot (20)

PPTX
Untangling - fall2017 - week5
PPTX
Untangling - fall2017 - week6
PPTX
Saving Time By Testing With Jest
PDF
Contributing to open source
PDF
RubyConf Taiwan 2016 - Large scale Rails applications
PDF
Angular ❤️ CMS from #AngularUp
PPTX
Week 8 intro to python
PPTX
Untangling the web - fall2017 - class 4
PDF
My Contributor Story
PDF
RubyConf China 2015 - Rails off assets pipeline
PDF
Whats next in templating
PDF
Reason React
PPT
Rails Vs CakePHP
PDF
The future of templating and frameworks
PDF
Making CLI app in ruby
PDF
So you think you can scale
PPTX
ASP.NET Core - Phillosophies, Processes and Tooling
PDF
SGCE 2015 REST APIs
PDF
Engage 2019: Modernising Your Domino and XPages Applications
PPTX
WordPress Development Environments
Untangling - fall2017 - week5
Untangling - fall2017 - week6
Saving Time By Testing With Jest
Contributing to open source
RubyConf Taiwan 2016 - Large scale Rails applications
Angular ❤️ CMS from #AngularUp
Week 8 intro to python
Untangling the web - fall2017 - class 4
My Contributor Story
RubyConf China 2015 - Rails off assets pipeline
Whats next in templating
Reason React
Rails Vs CakePHP
The future of templating and frameworks
Making CLI app in ruby
So you think you can scale
ASP.NET Core - Phillosophies, Processes and Tooling
SGCE 2015 REST APIs
Engage 2019: Modernising Your Domino and XPages Applications
WordPress Development Environments
Ad

Similar to Fast Web Applications with Go (20)

PDF
網頁程式設計
PDF
Desert Code Camp 2014: C#, the best programming language
PDF
Developing OpenResty Framework
PDF
Дмитрий Щадей "Что помогает нам писать качественный JavaScript-код?"
PDF
Rapid Prototyping With J Query
PDF
Clojure at ardoq
PDF
How to start developing apps for Firefox OS
PDF
Snakes on the Web; Developing web applications in python
PDF
Evaluation of Web Processing Service Frameworks
PDF
Go language presentation
PDF
Intro to node.js - Ran Mizrahi (27/8/2014)
PDF
Intro to node.js - Ran Mizrahi (28/8/14)
PDF
GoralSoft
PPTX
Single page applications the basics
PDF
Breaking up with Microsoft Word
PDF
Developer Efficiency
PDF
Web Fundamentals Crash Course
PDF
Web Fundamentals Crash Course
PDF
MozTW YZU CSE Lecture
KEY
HTML5 History & Features
網頁程式設計
Desert Code Camp 2014: C#, the best programming language
Developing OpenResty Framework
Дмитрий Щадей "Что помогает нам писать качественный JavaScript-код?"
Rapid Prototyping With J Query
Clojure at ardoq
How to start developing apps for Firefox OS
Snakes on the Web; Developing web applications in python
Evaluation of Web Processing Service Frameworks
Go language presentation
Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (28/8/14)
GoralSoft
Single page applications the basics
Breaking up with Microsoft Word
Developer Efficiency
Web Fundamentals Crash Course
Web Fundamentals Crash Course
MozTW YZU CSE Lecture
HTML5 History & Features
Ad

Recently uploaded (20)

PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
MYSQL Presentation for SQL database connectivity
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
KodekX | Application Modernization Development
PDF
Modernizing your data center with Dell and AMD
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Cloud computing and distributed systems.
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
MYSQL Presentation for SQL database connectivity
The AUB Centre for AI in Media Proposal.docx
Dropbox Q2 2025 Financial Results & Investor Presentation
KodekX | Application Modernization Development
Modernizing your data center with Dell and AMD
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Unlocking AI with Model Context Protocol (MCP)
Review of recent advances in non-invasive hemoglobin estimation
Digital-Transformation-Roadmap-for-Companies.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Encapsulation_ Review paper, used for researhc scholars
The Rise and Fall of 3GPP – Time for a Sabbatical?
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Mobile App Security Testing_ A Comprehensive Guide.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Cloud computing and distributed systems.

Fast Web Applications with Go

  • 1. Fast Web Applications with Go ! DevFestW Istanbul ! March 2,2014! Ekin Eylem Ozekin!
  • 2. Outline ! ²  Introduction to Go! ²  Web with Go! ²  Is Go suitable to Web! ²  Demo Web Application! ²  Questions !
  • 3. But First of All, Me ! •  Ekin Eylem Ozekin! •  BSc. In Computer Science, MSc. In Software Engineering! •  Currently, Ph.D. Candidate at Bogazici University, on Machine Learning! •  Works at GE !
  • 4. Introduction to Go ! •  Built around 2007, announced at 2009! •  By “GO”ogle! •  Open Source! •  Similar to C! •  Statically typed, compiled! •  No pointer arithmetic !
  • 5. Introduction to Go ! •  Automatic memory management, classes (structs), type inference! •  First class functions, suitable to functional programming! •  Concurrency support, channels !
  • 6. Introduction to Go ! •  Ideal for fast, distributed systems! •  Can import libraries directly from URLs! •  Built-in UTF-8 support (İ, Ğ etc. works perfectly)! •  Integrated AppEngine libraries !
  • 7. Introduction to Go ! package main! ! import (! "fmt"! "net/http"! )! ! func get_name() (string, string) {! // No reason to break a few rules, right! var hello = "Hello "! audience := "DevFestTR"! return hello, audience! }! ! func handler(writer http.ResponseWriter, request *http.Request) {! hello, audience := get_name()! fmt.Fprintf(writer, hello + audience)! }! ! func main() {! http.HandleFunc("/", handler)! http.ListenAndServe(":8080", nil)! } !
  • 8. Introduction to Go ! •  Written as read, left from right! •  No semicolons! •  Multiple return values (think of tuples in Python)! •  Single binary file after compile! •  More on the previous code later !
  • 9. Web with Go ! •  Built-in http package! •  Similar to J2EE Servlets! •  But more like a Micro-framework !
  • 10. Web with Go ! •  Web Development with the performance of C! •  Might be deployed with built-in server (port listener actually)! •  Deploy to Apache or Nginx with FastCGI! •  Also mod_go for Apache! •  Deploy to AppEngine or Heroku !
  • 11. Is Go Suitable for Web ! Should I use Go for Web? !
  • 12. Is Go Suitable for Web ! Pros! •  •  Micro-framework style http package! •  CGI support (kinda old but solid and useful)! •  Compiled, fast performance! •  C like Syntax but better! •  API is mature enough!
  • 13. Is Go Suitable for Web ! Cons! •  •  Not easier then PHP (or Ruby or Python)! •  Not as widely used as others! •  Not proven enough yet (can be argued)!
  • 14. Is Go Suitable for Web ! Last Word! •  •  Service Oriented Architecture and Micro Frameworks fit well! •  You don’t have to use just Go, use with others! •  Google already uses it (isn’t it enough reason?)!
  • 15. Demo ! A Web application with Go ! ! Let’s GO!
  • 16. Source Code ! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Server Side Code! package main! import ("html/template"; "fmt"; "net/http"; "strconv")! func main() {! http.HandleFunc("/", form)! http.HandleFunc("/show_age", form_handler)! http.ListenAndServe(":8080", nil)! }! func form(writer http.ResponseWriter,! request *http.Request) {! genderList := []string { "Male", "Female" }! t, _ := template.ParseFiles("form.html")! t.Execute(writer, map[string]interface{} {! "genders": genderList,! "title": "DevFest Applicant Form",! })! }! func form_handler(writer http.ResponseWriter,! request *http.Request) {! gender := request.FormValue("gender")! message := ""! if ("1" == gender) {! message = "You don't ask a woman her age."! } else {! age, _ := strconv.Atoi(request.FormValue("age"))! if (age < 1000) {! message = "This boy is still alive and kicking"! } else {! message = ”Still too young!"! } ! }! fmt.Fprintf(writer, message)! } ! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Template Code! <h1>{{.title}}</h1>! <p>! Fill in your gender and age.! <br />! And I will tell you if you are old or not...! </p>! <form action="/show_age" method="POST">! <dl>! <dt>Gender</dt>! <dd>! <select name="gender" style="width: 125px;">! {{range $index, $value := .genders}}! <option value="{{$index}}" />{{$value}}! {{end}}! </select>! </dd>! <dt>Age</dt>! <dd><input type="text" name="age" /></dd>! </dl>! <input type="submit" value="Save">! </form> !
  • 18. Questions? ! ? ! Thank you for listening! ! Ekin Eylem Ozekin! eeozekin@gmail.com !
  • 19. Q&A Session ! •  •  •  •  •  •  •  •  Is there a Database Abstraction layer?! As there are no classes ORM is a bit crippled. However, there are few implementations on that. You can find those here: http://jmoiron.net/blog/golang-orms/ . There are also bindings for popular databases: http://go-lang.cat-v.org/library-bindings! What can I use for User Interfaces?! There is a GTK binding for that. For more libraries you can check: http://go-lang.cat-v.org/library-bindings! To return multiple values Python returns actually a Tuple data structure. Is it similar in Go too?! No. Go really returns multiple values.! If I can something on a template, should I recompile in order to see changes?! No, you don’t. If you make a change on the template code, all you have to do is refresh the page. However you should be careful, when deploying to the server you should make sure that those templates exist too. !