Go Web Programming
Sau Sheong Chang
  • July 2016
  • ISBN 9781617292569
  • 312 pages
  • printed in black & white

As the importance of the Go language grows, the need for a great tutorial grows with it. This book fills this need.

Shaun Lippy, Oracle Corporation

Go Web Programming teaches you how to build scalable, high-performance web applications in Go using modern design principles.

Table of Contents detailed table of contents

Part 1: Introduction

1. Go and web applications

1.1. Using Go for web apps

1.1.1. Scalable web apps and Go

1.1.2. Modular web apps and Go

1.1.3. Maintainable web apps and Go

1.1.4. High performing web apps and Go

1.2. How web apps work

1.3. A quick introduction to HTTP

1.4. The coming of web apps

1.5. HTTP request

1.5.1. Request methods

1.5.2. Safe request methods

1.5.3. Idempotent request methods

1.5.4. Browser support for request methods

1.5.5. Request headers

1.6. HTTP response

1.6.1. Response status code

1.6.2. Response headers

1.7. URI

1.8. Introducing HTTP/2

1.9. Parts of a web app

1.9.1. Handler

1.9.2. Template engine

1.10. Hello Go

1.11. Summary

2. Go ChitChat

2.1. Let's ChitChat

2.2. Application design

2.3. Data model

2.4. Receiving and processing requests

2.4.1. The multiplexer

2.4.2. Serving static files

2.4.3. Creating the handler function

2.4.4. Access control using cookies

2.5. Generating HTML responses with templates

2.5.1. Tidying up

2.6. Installing PostgreSQL

2.6.1. Linux/FreeBSD

2.6.2. Mac OS X

2.6.3. Windows

2.7. Interfacing with the database

2.8. Starting the server

2.9. Wrapping up

2.10. Summary

Part 2: Basic Web Applications

3. Handling requests

3.1. The Go net/http library

3.2. Serving Go

3.2.1. The Go web server

3.2.2. Serving through HTTPS

3.3. Handlers and handler functions

3.3.1. Handling requests

3.3.2. More handlers

3.3.3. Handler functions

3.3.4. Chaining handlers and handler functions

3.3.5. ServeMux and DefaultServeMux

3.3.6. Other multiplexers

3.4. Using HTTP/2

3.5. Summary

4. Processing requests

4.1. Requests and responses

4.1.1. Request

4.1.2. Request URL

4.1.3. Request header

4.1.4. Request body

4.2. HTML forms and Go

4.2.1. Form

4.2.2. PostForm

4.2.3. MultipartForm

4.2.4. Files

4.2.5. Processing POST requests with JSON body

4.3. ResponseWriter

4.3.1. Writing to the ResponseWriter

4.4. Cookies

4.4.1. Cookies with Go

4.4.2. Sending cookies to the browser

4.4.3. Getting cookies from the browser

4.4.4. Using cookies for flash messages

4.5. Summary

5. Displaying content

5.1. Templates and template engines

5.2. The Go template engine

5.2.1. Parsing templates

5.2.2. Executing templates

5.3. Actions

5.3.1. Conditional actions

5.3.2. Iterator actions

5.3.3. Set actions

5.3.4. Include actions

5.4. Arguments, variables, and pipelines

5.5. Functions

5.6. Context awareness

5.6.1. Defending against XSS attacks

5.6.2. Unescaping HTML

5.7. Nesting templates

5.8. Using the block action to define default templates

5.9. Summary

6. Storing data

6.1. In-memory storage

6.2. File storage

6.2.1. Reading and writing CSV files

6.2.2. The gob package

6.3. Go and SQL

6.3.1. Setting up the database

6.3.2. Connecting to the database

6.3.3. Creating a post

6.3.4. Retrieving a post

6.3.5. Updating a post

6.3.6. Deleting a post

6.3.7. Getting all posts

6.4. Go and SQL relationships

6.4.1. Setting up the databases

6.4.2. One-to-many relationship

6.5. Go relational mappers

6.5.1. Sqlx

6.5.2. Gorm

6.6. Summary

Part 3: Being Real

7. Go web services

7.1. Introducing web services

7.2. Introducing SOAP-based web services

7.3. Introducing REST-based web services

7.3.1. Convert action to a resource

7.3.2. Make the action a property of the resource

7.4. Parsing and creating XML with Go

7.4.1. Parsing XML

7.4.2. Creating XML

7.5. Parsing and creating JSON with Go

7.5.1. Parsing JSON

7.5.2. Creating JSON

7.6. Creating Go web services

7.7. Summary

8. Testing your application

8.1. Go and testing

8.2. Unit testing with Go

8.2.1. Skipping test cases

8.2.2. Running tests in parallel

8.2.3. Benchmarking

8.3. HTTP testing with Go

8.4. Test doubles and dependency injection

8.4.1. Dependency injection with Go

8.5. Third-party Go testing libraries

8.5.1. Introducing the gocheck testing package

8.5.2. Introducing the Ginkgo testing framework

8.6. Summary

9. Leveraging Go concurrency

9.1. Concurrency isn't parallelism

9.2. Goroutines

9.2.1. Using goroutines

9.2.2. Goroutines and performance

9.2.3. Waiting for goroutines

9.3. Channels

9.3.1. Synchronization with channels

9.3.2. Message passing with channels

9.3.3. Buffered channels

9.3.4. Selecting channels

9.4. Concurrency for web applications

9.4.1. Creating the photo mosaic

9.4.2. The photo mosaic web application

9.4.3. Concurrent photo mosaic web application

9.5. Summary

10. Deploying Go

10.1. Deploying to servers

10.2. Deploying to Heroku

10.3. Deploying to Google App Engine

10.4. Deploying to Docker

10.4.1. What is Docker?

10.4.2. Installing Docker

10.4.3. Docker concepts and components

10.4.4. Dockerizing a Go web application

10.4.5. Pushing your Docker container to the internet

10.5. Comparison of deployment methods

10.6. Summary


Appendix A: Installing and setting up Go

A.1. Installing Go

A.1.1. Linux/FreeBSD

A.1.2. Windows

A.1.3. Mac OS X

A.2. Setting up Go

About the Technology

The Go language handles the demands of scalable, high-performance web applications by providing clean and fast compiled code, garbage collection, a simple concurrency model, and a fantastic standard library. It?s perfect for writing microservices or building scalable, maintainable systems.

About the book

Go Web Programming teaches you how to build web applications in Go using modern design principles. You?ll learn how to implement the dependency injection design pattern for writing test doubles, use concurrency in web applications, and create and consume JSON and XML in web services. Along the way, you?ll discover how to minimize your dependence on external frameworks, and you?ll pick up valuable productivity techniques for testing and deploying your applications.

What's inside

  • Basics
  • Testing and benchmarking
  • Using concurrency
  • Deploying to standalone servers, PaaS, and Docker
  • Dozens of tips, tricks, and techniques

About the reader

This book assumes you?re familiar with Go language basics and the general concepts of web development.

About the author

Sau Sheong Chang is Managing Director of Digital Technology at Singapore Power and an active contributor to the Ruby and Go communities.

combo $44.99 pBook + eBook + liveBook
eBook $35.99 pdf + ePub + kindle + liveBook

placing your order...

Don't refresh or navigate away from the page.

FREE domestic shipping on three or more pBooks