Go Web Programming
Summary

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

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

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.

Table of Contents

    PART 1 GO AND WEB APPLICATIONS
  1. Go and web applications
  2. Go ChitChat
  3. PART 2 BASIC WEB APPLICATIONS
  4. Handling requests
  5. Processing requests
  6. Displaying content
  7. Storing data
  8. PART 3 BEING REAL
  9. Go web services
  10. Testing your application
  11. Leveraging Go concurrency
  12. Deploying Go
"1124386642"
Go Web Programming
Summary

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

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

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.

Table of Contents

    PART 1 GO AND WEB APPLICATIONS
  1. Go and web applications
  2. Go ChitChat
  3. PART 2 BASIC WEB APPLICATIONS
  4. Handling requests
  5. Processing requests
  6. Displaying content
  7. Storing data
  8. PART 3 BEING REAL
  9. Go web services
  10. Testing your application
  11. Leveraging Go concurrency
  12. Deploying Go
34.99 In Stock
Go Web Programming

Go Web Programming

by Sau Sheong Chang
Go Web Programming

Go Web Programming

by Sau Sheong Chang

eBook

$34.99 

Available on Compatible NOOK devices, the free NOOK App and in My Digital Library.
WANT A NOOK?  Explore Now

Related collections and offers


Overview

Summary

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

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

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.

Table of Contents

    PART 1 GO AND WEB APPLICATIONS
  1. Go and web applications
  2. Go ChitChat
  3. PART 2 BASIC WEB APPLICATIONS
  4. Handling requests
  5. Processing requests
  6. Displaying content
  7. Storing data
  8. PART 3 BEING REAL
  9. Go web services
  10. Testing your application
  11. Leveraging Go concurrency
  12. Deploying Go

Product Details

ISBN-13: 9781638353409
Publisher: Manning
Publication date: 07/05/2016
Sold by: SIMON & SCHUSTER
Format: eBook
Pages: 312
File size: 5 MB

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.
Sau Sheong Chang is Managing Director of Digital Technology at Singapore Power and an active contributor to the Ruby and Go communities.

Table of Contents

Preface xiii

Acknowledgments xv

About this book xvii

About the cover illustration xx

Part 1 Go and web Applications 1

1 Go and web applications 3

1.1 Using Go for web applications 4

Scalable web applications and Go 4

Modular web applications and Go 5

Maintainable web applications and Go 5

High performing web applications and Go 6

1.2 How web applications work 6

1.3 A quick introduction to HTTP 8

1.4 The coming of web applications 8

1.5 HTTP request 9

Request methods 10

Safe request methods 11

Idempotenl request methods 11

Browser support for request methods 11

Request headers 11

1.6 HTTP response 12

Response status code 13

Response headers 13

1.7 URI 14

1.8 Introducing HTTP/2 16

1.9 Parts of a web app 16

Handler 16

Template engine 17

1.10 Hello Go 18

1.11 Summary 21

2 Go ChitChat 22

2.1 Let's ChitChat 23

2.2 Application design 24

2.3 Data model 26

2.4 Receiving and processing requests 27

The multiplexer 27

Serving static files 28

Creating the handler function 28

Access control using cookies 30

2.5 Generating HTML responses with templates 32

Tidying up 36

2.6 Installing PostgreSQL 37

Linux/FreeBSD 37 Mac OS X 38 Windows 38

2.7 Interfacing with the database 38

2.8 Starting the server 43

2.9 Wrapping up 43

2.10 Summary 44

Part 2 Basic Web Applications 45

3 Handling requests 47

3.1 The Go net/http library 48

3.2 Serving Go 50

The Go web server 50

Serving through HTTPS 51

3.3 Handlers and handler functions 55

Handling requests 55

More handlers 56

Handler functions 57

Chaining handlers and handler functions 59

ServeMux and DefaultServeMux 63

Other multiplexers 64

3.4 Using HTTP/2 66

3.5 Summary 68

4 Processing requests 69

4.1 Requests and responses 69

Request 70

Request URL 70

Request header 71 Request body 73

4.2 HTML forms and Go 74

Form 75

PostForm 77

MultipartForm 78

Files 80

Processing POST requests with JSON body 81

4.3 ResponseWriter 82

Writing to the ResponseWriter 83

4.4 Cookies 87

Cookies with Go 87

Sending cookies to the browser 88

Getting cookies from the browser 90

Using cookies for flash messages 92

4.5 Summary 95

5 Displaying content 96

5.1 Templates and template engines 97

5.2 The Go template engine 98

Parsing templates 100

Executing templates 101

5.3 Actions 102

Conditional actions 102

Iterator actions 104 Set actions 105

Include actions 107

5.4 Arguments, variables, and pipelines 110

5.5 Functions 111

5.6 Context awareness 113

Defending against XSS attacks 116

Unescaping HTML 118

5.7 Nesting templates 119

5.8 Using the block action to define default templates 123

5.9 Summary 124

6 Storing data 125

6.1 In-memory storage 126

6.2 File storage 128

Reading and writing CSV files 130

The gob package 132

6.3 Go and SQL 134

Setting up the database 134

Connecting to the database 137

Creating a post 138

Retrieving a post 140

Updating a post 141

Deleting a post 141

Getting all posts 142

6.4 Go and SQL relationships 143

Setting up the databases 143

One-to-many relationship 145

6.5 Go relational mappers 147

Sqlx 148

Gorm 149

6.6 Summary 152

Part 3 Being Real 153

7 Go web services 155

7.1 Introducing web services 155

7.2 Introducing SOAP-based web services 157

7.3 Introducing REST-based web services 160

Convert action to a resource 162

Make the action a property of the resource 163

7.4 Parsing and creating XML with Go 163

Parsing XML 163

Creating XML 171

7.5 Parsing and creating JSON with Go 174

Parsing JSON 175

Creating JSON 178

7.6 Creating Go web services 181

7.7 Summary 188

8 Testing your application 190

8.1 Go and testing 191

8.2 Unit testing with Go 191

Skipping test cases 195

Running tests in parallel 196

Benchmarking 197

8.3 HTTP testing with Go 200

8.4 Test doubles and dependency injection 204

Dependency injection with Go 205

8.5 Third-party Go testing libraries 210

Introducing the gocheck testing package 211

Introducing the Ginkgo testing framework 216

8.6 Summary 221

9 Leveraging Go concurrency 223

9.1 Concurrency isn't parallelism 223

9.2 Goroutines 225

Using garoutines 225

Goroutines and performance 228

Waiting for goroutines 231

9.3 Channels 232

Synchronization with channels 233

Message passing with channels 234

Buffered channels 235

Selecting channels 237

9.4 Concurrency for web applications 240

Creating the photo mosaic 240

The photo mosaic web application 243

Concurrent photo mosaic web application 247

9.5 Summary 254

10 Deploying Go 256

10.1 Deploying to servers 257

10.2 Deploying to Heroku 263

10.3 Deploying to Google App Engine 266

10.4 Deploying to Docker 271

What is Docker? 271

Installing Docker 272

Docker concepts and components 273

Dockerizing a Go web application 274

Pushing your Docker container to the internet 276

10.5 Comparison of deployment methods 279

10.6 Summary 280

Appendix Installing and setting up Go 281

Index 285

From the B&N Reads Blog

Customer Reviews