SlideShare a Scribd company logo
Building Your First Web
App in Go
Andy Watson
Ionic Security
#ATOWebGo #ATO2015
All Things Open
2015
About Me
Who: Andy Watson
What: Code Flinger
Where: Ionic Security
http://ionic.com/ @andrewwatson
I used to write PHP
Lots of PHP.
Tons.
I’m a Gopher Now
Take the Tour at golang.org
Web Apps in Go
• No need for a wrapper like Apache or Nginx
• Create a self-contained, statically compiled
binary
• Cross Compile from your laptop to your
server architecture
Simple Web App
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello, worldn")
})
fmt.Print("Listening on :8080n")
http.ListenAndServe(":8080", nil)
}
Templates
Easily render well formed HTML using data
from your application
Nest templates inside each other (partials) for
easy re-use
Simple Template Example
func handleRoot(w http.ResponseWriter, req *http.Request) {
var templateStr =
"<html><body><h1>{{.}}</h1></body></html>n"
var templ =
template.Must(template.New("qr").Parse(templateStr))
templ.Execute(w, "Hello!")
}
func main() {
http.HandleFunc("/", handleRoot)
fmt.Print("Listening on :8080n")
http.ListenAndServe(":8080", nil)
}
Simple Logic
{{if .}}
<h1><a
href="{{.}}">Something!</a>
{{else}}
<h1>None</h1>
{{end}}
Iterations
type Book struct {
Author, Title string
}
func handler(w http.ResponseWriter, r *http.Request) {
// var bookList Book[]
bookList, err := lookupBooksForSale()
templ.Execute(w, bookList)
}
Template with range Operator
<h1>Books For Sale</h1>
{{range .}}
<h3>{{.Title}} by {{.Author}} </h3>
{{else}}
<h3>Sorry.</h3>
{{end}}
Outputs
<h3>Sorry.</h3> <h3>The Thing by
Stephen King</h3>
<h3>Moby Dick by
Herman Melville</h3>
With Empty List With Data
It’s the Methods, man!
func uploadHandler(…) {
if r.Method != "POST" {
err := doPostThings()
handleErrors(err)
return
}
}
Routing
Use a routing library like httprouter or mux to
match requests to handlers
Routes defined using paths and HTTP verbs
r := httprouter.New()
r.POST(”/login", LoginHandler)
r.GET("/", HomeHandler)
MiddleWare
Gets executed with every request
Used for logging, instrumentation, error
handling and more
Negroni
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "Welcome to the home page!")
})
n := negroni.Classic()
n.UseHandler(mux)
n.Run(":3000")
}
https://github.com/codegangsta/negroni
Negroni Classic
Common set of middleware
• Logging
• Recovery (from panics)
• Static Content Handling
Render
• Cleans Up boilerplate template rendering code
• Handles Errors
• Takes care of headers for HTML, JSON, XML
etc
https://github.com/unrolled/render
Context
• Stores values shared during a request
lifetime
• Useful for easily passing the full context of a
request to multiple handlers
http://www.gorillatoolkit.org/pkg/context
Sessions
Keep data between requests to maintain state
• User information
• Shopping Cart
• ETC
http://www.gorillatoolkit.org/pkg/sessions
Setting up Session Handling
var sessionstore = sessions.NewCookieStore([]byte(secret))
func init() {
sessionstore.Options = &sessions.Options{
Path: "/",
MaxAge: 3600,
HttpOnly: true,
}
}
Using Sessions
session, _ := sessionstore.Get(req, "OthrNumbr-session")
session.Values["loggedin"] = true
session.Values["cust_id"] = cust.CustomerId
session.Values["description"] = cust.Description
session.Save(req, w)
http.Redirect(w, req, "/home/", 302)
Rapid Development
• Gin wraps your process
• Recompiles and Restarts Automatically
• https://github.com/codegangsta/gin
Deploy to Production
• Cross Compile for Linux
• SCP to production
• Wrap in upstart script etc
Get up
and Go
Contain Yourself
The GoLang library Docker images make it
easy to build and run your Go app in a
container
https://hub.docker.com/_/golang/
Dockerfile
FROM golang:1.5-onbuild
Docker Commands
$ docker build -t hello-world .
$ docker run --rm -it --name fred hello-world
Google App Engine
• GAE supports Go runtime
• Automatically scales up instances
• Provides highly available datastore
• Supports Go 1.4 at this time
• Soon: Migrate GAE to Managed VMs
https://cloud.google.com/appengine/
GAE DataStore
type Greeting struct {
Author string
Content string
Date time.Time
}
Fetch from DataStore
func root(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
q := datastore.NewQuery("Greeting").
Ancestor(guestbookKey(c)).Order("-Date").Limit(10)
greetings := make([]Greeting, 0, 10)
if _, err := q.GetAll(c, &greetings); err != nil {
http.Error(w, err.Error(),500)
return
}
}
GAE Example
https://github.com/GoogleCloudPlatform/appen
gine-guestbook-go
Shows session handling, data storage,
authentication and more
Other Resources
Building Web Apps with Go – by codegangtsa
http://bit.ly/WebAppsWithGo
Google Cloud Platform - Go
http://bit.ly/GoGoogleCloud
Deployed To GAE
SMS Voting Application for CSS Dev Conf
• Takes votes via SMS (Twilio) and stores
them in GAE Datastore
• Outputs them as CSV
Deployed to GAE
OthrNumbr
• Burner Numbers for
texting with strangers
• Written in Go, Deployed
on App Engine
• Users Datastore,
memcache, Twilio, Stripe
http://othrnumbr.com/
@andrewwatson
http://about.me/andrewwatson
Thank You
Kitty wants to learn concurrency
Concurrency in Go
• In Go, concurrency is accomplished by
passing shared values around on channels
• Not by sharing memory between threads
Repeat After Me
“Do not communicate by sharing
memory; instead, share memory by
communicating.”
Concurrent Routines
Created by putting “go” in front of function calls
func Announce(message string, delay time.Duration) {
go func() {
time.Sleep(delay)
fmt.Println(message)
}() // Note the parentheses - must call the function.
}
https://golang.org/doc/effective_go.html#concurrency
Channels
Go has a built in primitive types for
communicating between goroutines
c := make(chan int) // Allocate a channel.
// Start the sort in a goroutine; when it completes, signal on the channel.
go func() {
list.Sort()
c <- 1 // Send a signal; value does not matter.
}()
doSomethingForAWhile()
<-c // Wait for sort to finish; discard sent value.
Channels
• Can be buffered or unbuffered
• Can be declared to carry any other type,
even channels!
Concurrency in Go
The essential guides:
http://bit.ly/ConcurrentGo
http://bit.ly/AdvancedGoConcurrency

More Related Content

PDF
Provisioning Servers Made Easy
PPTX
OpenStack 101 - All Things Open 2015
PPTX
Monitoring Docker containers - Docker NYC Feb 2015
PDF
NATS: Simple, Secure and Scalable Messaging For the Cloud Native Era
PDF
Develop and Deploy Cloud-Native Apps as Resilient Microservice Architectures
PDF
Nginx conference 2015
PDF
Secrets in Kubernetes
PDF
Testing at Stream-Scale
Provisioning Servers Made Easy
OpenStack 101 - All Things Open 2015
Monitoring Docker containers - Docker NYC Feb 2015
NATS: Simple, Secure and Scalable Messaging For the Cloud Native Era
Develop and Deploy Cloud-Native Apps as Resilient Microservice Architectures
Nginx conference 2015
Secrets in Kubernetes
Testing at Stream-Scale

What's hot (20)

PPT
Open stack swift architecture and monitoring
PDF
2 Day Bootcamp for OpenStack--Cloud Training by Mirantis (Preview)
PPTX
Cloud Computing Open Stack Compute Node
PPTX
OpenStack Introduction
PDF
An Introduction to OpenStack
PDF
Kubernetes security and you
PPTX
Structured Container Delivery by Oscar Renalias, Accenture
PDF
Infrastructure-as-code: bridging the gap between Devs and Ops
PDF
Security model for a remote company
PDF
KURMA - A Containerized Container Platform - KubeCon 2016
PDF
The Future of SDN in CloudStack by Chiradeep Vittal
PDF
Kubernetes Summit 2019 - Harden Your Kubernetes Cluster
PDF
Introduction to OpenStack : Barcamp Bangkhen 2016
PDF
New Features of Kubernetes v1.2.0 beta
PDF
OpenStack Cloud Tutorial | What is OpenStack | OpenStack Tutorial | OpenStack...
PDF
Introduction to cloud and openstack
PPT
CloudStack Clients and Tools
PDF
Vancouver open stack meetup presentation
PPT
Openstack - An introduction/Installation - Presented at Dr Dobb's conference...
PPTX
Building Angular 2.0 applications with TypeScript
Open stack swift architecture and monitoring
2 Day Bootcamp for OpenStack--Cloud Training by Mirantis (Preview)
Cloud Computing Open Stack Compute Node
OpenStack Introduction
An Introduction to OpenStack
Kubernetes security and you
Structured Container Delivery by Oscar Renalias, Accenture
Infrastructure-as-code: bridging the gap between Devs and Ops
Security model for a remote company
KURMA - A Containerized Container Platform - KubeCon 2016
The Future of SDN in CloudStack by Chiradeep Vittal
Kubernetes Summit 2019 - Harden Your Kubernetes Cluster
Introduction to OpenStack : Barcamp Bangkhen 2016
New Features of Kubernetes v1.2.0 beta
OpenStack Cloud Tutorial | What is OpenStack | OpenStack Tutorial | OpenStack...
Introduction to cloud and openstack
CloudStack Clients and Tools
Vancouver open stack meetup presentation
Openstack - An introduction/Installation - Presented at Dr Dobb's conference...
Building Angular 2.0 applications with TypeScript
Ad

Similar to How to Build Your First Web App in Go (20)

PDF
(Ebook) Go: Building Web Applications by Nathan Kozyra, Mat Ryer
PDF
Complete Download (Ebook) Go: Building Web Applications by Nathan Kozyra, M...
PDF
Go Building Web Applications 1st Edition Nathan Kozyra Mat Ryer
PDF
Instant Access to Go Building Web Applications 1st Edition Nathan Kozyra Mat ...
PDF
(Ebook) Go: Building Web Applications by Nathan Kozyra, Mat Ryer
PDF
Go Building Web Applications 1st Edition Nathan Kozyra Mat Ryer download pdf
PDF
Download full Go Building Web Applications 1st Edition Nathan Kozyra Mat Ryer...
PDF
Go Building Web Applications 1st Edition Nathan Kozyra Mat Ryer
PDF
Go Web Programming 1st Edition Sau Sheong Chang
PDF
Lessons Learned from Building a REST API on Google App Engine
PDF
13 practical tips for writing secure golang applications
PDF
1.6 米嘉 gobuildweb
PDF
Go Web Programming 1st Edition Sau Sheong Chang
PDF
LCA2014 - Introduction to Go
PPTX
Golang slidesaudrey
PDF
Import golang; struct microservice
PPTX
Go from a PHP Perspective
PDF
Physical Computing Using Go and Arduino
PDF
Fast Web Applications with Go
PDF
Intro to GO (Bangkok Launchpad 2014)
(Ebook) Go: Building Web Applications by Nathan Kozyra, Mat Ryer
Complete Download (Ebook) Go: Building Web Applications by Nathan Kozyra, M...
Go Building Web Applications 1st Edition Nathan Kozyra Mat Ryer
Instant Access to Go Building Web Applications 1st Edition Nathan Kozyra Mat ...
(Ebook) Go: Building Web Applications by Nathan Kozyra, Mat Ryer
Go Building Web Applications 1st Edition Nathan Kozyra Mat Ryer download pdf
Download full Go Building Web Applications 1st Edition Nathan Kozyra Mat Ryer...
Go Building Web Applications 1st Edition Nathan Kozyra Mat Ryer
Go Web Programming 1st Edition Sau Sheong Chang
Lessons Learned from Building a REST API on Google App Engine
13 practical tips for writing secure golang applications
1.6 米嘉 gobuildweb
Go Web Programming 1st Edition Sau Sheong Chang
LCA2014 - Introduction to Go
Golang slidesaudrey
Import golang; struct microservice
Go from a PHP Perspective
Physical Computing Using Go and Arduino
Fast Web Applications with Go
Intro to GO (Bangkok Launchpad 2014)
Ad

More from All Things Open (20)

PDF
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
PPTX
Big Data on a Small Budget: Scalable Data Visualization for the Rest of Us - ...
PDF
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
PDF
Let's Create a GitHub Copilot Extension! - Nick Taylor, Pomerium
PDF
Leveraging Pre-Trained Transformer Models for Protein Function Prediction - T...
PDF
Gen AI: AI Agents - Making LLMs work together in an organized way - Brent Las...
PDF
You Don't Need an AI Strategy, But You Do Need to Be Strategic About AI - Jes...
PPTX
DON’T PANIC: AI IS COMING – The Hitchhiker’s Guide to AI - Mark Hinkle, Perip...
PDF
Fine-Tuning Large Language Models with Declarative ML Orchestration - Shivay ...
PDF
Leveraging Knowledge Graphs for RAG: A Smarter Approach to Contextual AI Appl...
PPTX
Artificial Intelligence Needs Community Intelligence - Sriram Raghavan, IBM R...
PDF
Don't just talk to AI, do more with AI: how to improve productivity with AI a...
PPTX
Open-Source GenAI vs. Enterprise GenAI: Navigating the Future of AI Innovatio...
PDF
The Death of the Browser - Rachel-Lee Nabors, AgentQL
PDF
Making Operating System updates fast, easy, and safe
PDF
Reshaping the landscape of belonging to transform community
PDF
The Unseen, Underappreciated Security Work Your Maintainers May (or may not) ...
PDF
Integrating Diversity, Equity, and Inclusion into Product Design
PDF
The Open Source Ecosystem for eBPF in Kubernetes
PDF
Open Source Privacy-Preserving Metrics - Sarah Gran & Brandon Pitman
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
Big Data on a Small Budget: Scalable Data Visualization for the Rest of Us - ...
AI 3-in-1: Agents, RAG, and Local Models - Brent Laster
Let's Create a GitHub Copilot Extension! - Nick Taylor, Pomerium
Leveraging Pre-Trained Transformer Models for Protein Function Prediction - T...
Gen AI: AI Agents - Making LLMs work together in an organized way - Brent Las...
You Don't Need an AI Strategy, But You Do Need to Be Strategic About AI - Jes...
DON’T PANIC: AI IS COMING – The Hitchhiker’s Guide to AI - Mark Hinkle, Perip...
Fine-Tuning Large Language Models with Declarative ML Orchestration - Shivay ...
Leveraging Knowledge Graphs for RAG: A Smarter Approach to Contextual AI Appl...
Artificial Intelligence Needs Community Intelligence - Sriram Raghavan, IBM R...
Don't just talk to AI, do more with AI: how to improve productivity with AI a...
Open-Source GenAI vs. Enterprise GenAI: Navigating the Future of AI Innovatio...
The Death of the Browser - Rachel-Lee Nabors, AgentQL
Making Operating System updates fast, easy, and safe
Reshaping the landscape of belonging to transform community
The Unseen, Underappreciated Security Work Your Maintainers May (or may not) ...
Integrating Diversity, Equity, and Inclusion into Product Design
The Open Source Ecosystem for eBPF in Kubernetes
Open Source Privacy-Preserving Metrics - Sarah Gran & Brandon Pitman

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Encapsulation theory and applications.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Approach and Philosophy of On baking technology
PDF
KodekX | Application Modernization Development
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
A Presentation on Artificial Intelligence
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Machine learning based COVID-19 study performance prediction
Advanced methodologies resolving dimensionality complications for autism neur...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Dropbox Q2 2025 Financial Results & Investor Presentation
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Encapsulation theory and applications.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Approach and Philosophy of On baking technology
KodekX | Application Modernization Development
Unlocking AI with Model Context Protocol (MCP)
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The AUB Centre for AI in Media Proposal.docx
“AI and Expert System Decision Support & Business Intelligence Systems”
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
A Presentation on Artificial Intelligence
Spectral efficient network and resource selection model in 5G networks
Building Integrated photovoltaic BIPV_UPV.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Machine learning based COVID-19 study performance prediction

How to Build Your First Web App in Go

  • 1. Building Your First Web App in Go Andy Watson Ionic Security #ATOWebGo #ATO2015 All Things Open 2015
  • 2. About Me Who: Andy Watson What: Code Flinger Where: Ionic Security http://ionic.com/ @andrewwatson
  • 3. I used to write PHP Lots of PHP. Tons.
  • 5. Take the Tour at golang.org
  • 6. Web Apps in Go • No need for a wrapper like Apache or Nginx • Create a self-contained, statically compiled binary • Cross Compile from your laptop to your server architecture
  • 7. Simple Web App package main import ( "fmt" "net/http" ) func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "Hello, worldn") }) fmt.Print("Listening on :8080n") http.ListenAndServe(":8080", nil) }
  • 8. Templates Easily render well formed HTML using data from your application Nest templates inside each other (partials) for easy re-use
  • 9. Simple Template Example func handleRoot(w http.ResponseWriter, req *http.Request) { var templateStr = "<html><body><h1>{{.}}</h1></body></html>n" var templ = template.Must(template.New("qr").Parse(templateStr)) templ.Execute(w, "Hello!") } func main() { http.HandleFunc("/", handleRoot) fmt.Print("Listening on :8080n") http.ListenAndServe(":8080", nil) }
  • 11. Iterations type Book struct { Author, Title string } func handler(w http.ResponseWriter, r *http.Request) { // var bookList Book[] bookList, err := lookupBooksForSale() templ.Execute(w, bookList) }
  • 12. Template with range Operator <h1>Books For Sale</h1> {{range .}} <h3>{{.Title}} by {{.Author}} </h3> {{else}} <h3>Sorry.</h3> {{end}}
  • 13. Outputs <h3>Sorry.</h3> <h3>The Thing by Stephen King</h3> <h3>Moby Dick by Herman Melville</h3> With Empty List With Data
  • 14. It’s the Methods, man! func uploadHandler(…) { if r.Method != "POST" { err := doPostThings() handleErrors(err) return } }
  • 15. Routing Use a routing library like httprouter or mux to match requests to handlers Routes defined using paths and HTTP verbs r := httprouter.New() r.POST(”/login", LoginHandler) r.GET("/", HomeHandler)
  • 16. MiddleWare Gets executed with every request Used for logging, instrumentation, error handling and more
  • 17. Negroni func main() { mux := http.NewServeMux() mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "Welcome to the home page!") }) n := negroni.Classic() n.UseHandler(mux) n.Run(":3000") } https://github.com/codegangsta/negroni
  • 18. Negroni Classic Common set of middleware • Logging • Recovery (from panics) • Static Content Handling
  • 19. Render • Cleans Up boilerplate template rendering code • Handles Errors • Takes care of headers for HTML, JSON, XML etc https://github.com/unrolled/render
  • 20. Context • Stores values shared during a request lifetime • Useful for easily passing the full context of a request to multiple handlers http://www.gorillatoolkit.org/pkg/context
  • 21. Sessions Keep data between requests to maintain state • User information • Shopping Cart • ETC http://www.gorillatoolkit.org/pkg/sessions
  • 22. Setting up Session Handling var sessionstore = sessions.NewCookieStore([]byte(secret)) func init() { sessionstore.Options = &sessions.Options{ Path: "/", MaxAge: 3600, HttpOnly: true, } }
  • 23. Using Sessions session, _ := sessionstore.Get(req, "OthrNumbr-session") session.Values["loggedin"] = true session.Values["cust_id"] = cust.CustomerId session.Values["description"] = cust.Description session.Save(req, w) http.Redirect(w, req, "/home/", 302)
  • 24. Rapid Development • Gin wraps your process • Recompiles and Restarts Automatically • https://github.com/codegangsta/gin
  • 25. Deploy to Production • Cross Compile for Linux • SCP to production • Wrap in upstart script etc
  • 27. Contain Yourself The GoLang library Docker images make it easy to build and run your Go app in a container https://hub.docker.com/_/golang/
  • 29. Docker Commands $ docker build -t hello-world . $ docker run --rm -it --name fred hello-world
  • 30. Google App Engine • GAE supports Go runtime • Automatically scales up instances • Provides highly available datastore • Supports Go 1.4 at this time • Soon: Migrate GAE to Managed VMs https://cloud.google.com/appengine/
  • 31. GAE DataStore type Greeting struct { Author string Content string Date time.Time }
  • 32. Fetch from DataStore func root(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) q := datastore.NewQuery("Greeting"). Ancestor(guestbookKey(c)).Order("-Date").Limit(10) greetings := make([]Greeting, 0, 10) if _, err := q.GetAll(c, &greetings); err != nil { http.Error(w, err.Error(),500) return } }
  • 34. Other Resources Building Web Apps with Go – by codegangtsa http://bit.ly/WebAppsWithGo Google Cloud Platform - Go http://bit.ly/GoGoogleCloud
  • 35. Deployed To GAE SMS Voting Application for CSS Dev Conf • Takes votes via SMS (Twilio) and stores them in GAE Datastore • Outputs them as CSV
  • 36. Deployed to GAE OthrNumbr • Burner Numbers for texting with strangers • Written in Go, Deployed on App Engine • Users Datastore, memcache, Twilio, Stripe http://othrnumbr.com/
  • 38. Kitty wants to learn concurrency
  • 39. Concurrency in Go • In Go, concurrency is accomplished by passing shared values around on channels • Not by sharing memory between threads
  • 40. Repeat After Me “Do not communicate by sharing memory; instead, share memory by communicating.”
  • 41. Concurrent Routines Created by putting “go” in front of function calls func Announce(message string, delay time.Duration) { go func() { time.Sleep(delay) fmt.Println(message) }() // Note the parentheses - must call the function. } https://golang.org/doc/effective_go.html#concurrency
  • 42. Channels Go has a built in primitive types for communicating between goroutines c := make(chan int) // Allocate a channel. // Start the sort in a goroutine; when it completes, signal on the channel. go func() { list.Sort() c <- 1 // Send a signal; value does not matter. }() doSomethingForAWhile() <-c // Wait for sort to finish; discard sent value.
  • 43. Channels • Can be buffered or unbuffered • Can be declared to carry any other type, even channels!
  • 44. Concurrency in Go The essential guides: http://bit.ly/ConcurrentGo http://bit.ly/AdvancedGoConcurrency

Editor's Notes

  • #2: Hello everyone, thank you for coming. I’m Andy Watson and I’m here to talk to you about ways to use cryptography correctly in your applications
  • #3: I’m currently a senior engineer at Ionic Security which is a data protection security company based out of Atlanta, GA I’ve been a software developer professionally since 1996 when I got my first job developing large scale, distributed systems for processing streams of data collected out of particle accelerators with some Physics professors at FSU. This was “cloud” computing before it had a name. Since then I’ve built mobile, desktop and web applications for companies like The Walt Disney World Resort, Maersk Sealand, Cox Communications, CoffeeCup Software and many many others.