Go: Design Patterns for Real-World Projects

An insightful guide to learning the Go programming language
Preview in Mapt
Code Files

Go: Design Patterns for Real-World Projects

Vladimir Vivien, Mario Castro Contreras, Mat Ryer

4 customer reviews
An insightful guide to learning the Go programming language
Mapt Subscription
FREE
$29.99/m after trial
eBook
$50.40
RRP $71.99
Save 29%
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$50.40
$29.99p/m after trial
RRP $71.99
Subscription
eBook
Start 30 Day Trial

Frequently bought together


Go: Design Patterns for Real-World Projects Book Cover
Go: Design Patterns for Real-World Projects
$ 71.99
$ 50.40
Go: Building 7 Real-World Projects Book Cover
Go: Building 7 Real-World Projects
$ 124.99
$ 106.25
Buy 2 for $35.00
Save $161.98
Add to Cart
Subscribe and access every Packt eBook & Video.
 
  • 5,000+ eBooks & Videos
  • 50+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 

Book Details

ISBN 139781788390552
Paperback1091 pages

Book Description

The Go programming language has firmly established itself as a favorite for building complex and scalable system applications. Go offers a direct and practical approach to programming that lets programmers write correct and predictable code using concurrency idioms and a full-featured standard library. This practical guide is full of real-world examples to help you get started with Go in no time at all.

You’ll start by understanding the fundamentals of Go, then get a detailed description of the Go data types, program structures, and Maps. After that, you’ll learn how to use Go concurrency idioms to avoid pitfalls and create programs that are exact in expected behavior. Next, you will get familiar with the tools and libraries that are available in Go to write and exercise tests, benchmarking, and code coverage. After that, you will be able to utilize some of the most important features of GO such as Network Programming and OS integration to build efficient applications.

Then you’ll start applying your skills to build some amazing projects in Go. You will learn to develop high-quality command-line tools that utilize the powerful shell capabilities and perform well using Go’s built-in concurrency mechanisms. Scale, performance, and high availability lie at the heart of our projects, and the lessons learned throughout the sections will arm you with everything you need to build world-class solutions. You will get a feel for app deployment using Docker and Google App Engine. Each project could form the basis of a start-up, which means they are directly applicable to modern software markets. With these skills in hand, you will be able to conquer all your fears of application development and go on to build large, robust and succinct apps in Go.

This Learning Path combines some of the best that Packt has to offer in one complete, curated package. It includes content from the following Packt products:

  1. Learning Go Programming
  2. Go Design Patterns
  3. Go Programming Blueprints, Second Edition

Table of Contents

Chapter 1: A First Step in Go
The Go programming language
Playing with Go
Your first Go program
Go in a nutshell
Summary
Chapter 2: Go Language Essentials
The Go source file
Go identifiers
Go variables
Go constants
Go operators
Summary
Chapter 3: Go Control Flow
The if statement
Switch statements
The for statements
The break, continue, and goto statements
Summary
Chapter 4: Data Types
Go types
Numeric types
Boolean type
Rune and string types
Pointers
Type declaration
Type conversion
Summary
Chapter 5: Functions in Go
Go functions
Passing parameter values
Higher-order functions
Error signaling and handling
Deferring function calls
Function panic and recovery
Summary
Chapter 6: Go Packages and Programs
The Go package
Creating packages
Building packages
Package visibility
Importing package
Package initialization
Creating programs
Remote packages
Summary
Chapter 7: Composite Types
The array type
The slice type
The map type
The struct type
Summary
Chapter 8: Methods, Interfaces, and Objects
Go methods
Objects in Go
The interface type
Type assertion
Summary
Chapter 9: Concurrency
Goroutines
Channels
Writing concurrent programs
The sync package
Detecting race conditions
Parallelism in Go
Summary
Chapter 10: Data IO in Go
IO with readers and writers
The io.Reader interface
The io.Writer interface
Working with the io package
Working with files
Formatted IO with fmt
Buffered IO
In-memory IO
Encoding and decoding data
Summary
Chapter 11: Writing Networked Services
The net package
A TCP API server
The HTTP package
A JSON API server
Summary
Chapter 12: Code Testing
The Go test tool
Writing Go tests
HTTP testing
Test coverage
Code benchmark
Summary
Chapter 13: Ready... Steady... Go!
A little bit of history
Installing Go
Starting with Hello World
Integrated Development Environment - IDE
Types
Variables and constants
Operators
Flow control
Functions
Arrays, slices, and maps
Visibility
Zero-initialization
Pointers and structures
Interfaces
Testing and TDD
Libraries
The Go get tool
Managing JSON data
Go tools
Contributing to Go open source projects in GitHub
Summary
Chapter 14: Creational Patterns - Singleton, Builder, Factory, Prototype, and Abstract Factory Design Patterns
Singleton design pattern - having a unique instance of a type in the entire program
Builder design pattern - reusing an algorithm to create many implementations of an interface
Factory method - delegating the creation of different types of payments
Abstract Factory - a factory of factories
Prototype design pattern
Summary
Chapter 15: Structural Patterns - Composite, Adapter, and Bridge Design Patterns
Composite design pattern
Adapter design pattern
Bridge design pattern
Summary
Chapter 16: Structural Patterns - Proxy, Facade, Decorator, and Flyweight Design Patterns
Proxy design pattern
Decorator design pattern
Facade design pattern
Flyweight design pattern
Summary
Chapter 17: Behavioral Patterns - Strategy, Chain of Responsibility, and Command Design Patterns
Strategy design pattern
Chain of responsibility design pattern
Command design pattern
Summary
Chapter 18: Behavioral Patterns - Template, Memento, and Interpreter Design Patterns
Template design pattern
Memento design pattern
Interpreter design pattern
Summary
Chapter 19: Behavioral Patterns - Visitor, State, Mediator, and Observer Design Patterns
Visitor design pattern
State design pattern
Mediator design pattern
Observer design pattern
Chapter 20: Introduction to Gos Concurrency
A little bit of history and theory
Goroutines
Callbacks
Mutexes
Channels
Using it all - concurrent singleton
Summary
Chapter 21: Concurrency Patterns - Barrier, Future, and Pipeline Design Patterns
Barrier concurrency pattern
Future design pattern
Pipeline design pattern
Summary
Chapter 22: Concurrency Patterns - Workers Pool and Publish/Subscriber Design Patterns
Workers pool
Concurrent Publish/Subscriber design pattern
Summary
Chapter 23: Chat Application with Web Sockets
A simple web server
Modeling a chat room and clients on the server
Building an HTML and JavaScript chat client
Tracing code to get a look under the hood
Summary
Chapter 24: Adding User Accounts
Handlers all the way down
Making a pretty social sign-in page
Endpoints with dynamic paths
Getting started with OAuth2
Tell the authorization providers about your app
Implementing external logging in
Summary
Chapter 25: Three Ways to Implement Profile Pictures
Avatars from the OAuth2 server
Implementing Gravatar
Uploading an avatar picture
Combining all three implementations
Summary
Chapter 26: Command-Line Tools to Find Domain Names
Pipe design for command-line tools
Five simple programs
Composing all five programs
Summary
Chapter 27: Building Distributed Systems and Working with Flexible Data
The system design
Installing the environment
Reading votes from Twitter
Counting votes
Running our solution
Summary
Chapter 28: Exposing Data and Functionality through a RESTful Data Web Service API
RESTful API design
Sharing data between handlers
Wrapping handler functions
Injecting dependencies
Responding
Understanding the request
Serving our API with one function
Handling endpoints
A web client that consumes the API
Running the solution
Summary
Chapter 29: Random Recommendations Web Service
The project overview
Representing data in code
Generating random recommendations
Summary
Chapter 30: Filesystem Backup
Solution design
The backup package
The user command-line tool
The daemon backup tool
Testing our solution
Summary
Chapter 31: Building a Q&A Application for Google App Engine
The Google App Engine SDK for Go
Google Cloud Datastore
Entities and data access
Google App Engine users
Transactions in Google Cloud Datastore
Querying in Google Cloud Datastore
Votes
Casting a vote
Exposing data operations over HTTP
Running apps with multiple modules
Deploying apps with multiple modules
Summary
Chapter 32: Micro-services in Go with the Go kit Framework
Introducing gRPC
Protocol buffers
Building the service
Modeling method calls with requests and responses
An HTTP server in Go kit
A gRPC server in Go kit
Creating a server command
Building a gRPC client
Rate limiting with service middleware
Summary
Chapter 33: Deploying Go Applications Using Docker
Using Docker locally
Deploying Docker images
Deploying to Digital Ocean
Summary

What You Will Learn

  • Install and configure the Go development environment to quickly get started with your first program
  • Use the basic elements of the language including source code structure, variables, constants, and control flow primitives
  • Get to know all the basic syntax and tools you need to start coding in Go
  • Create unique instances that cannot be duplicated within a program
  • Build quirky and fun projects from scratch while exploring patterns, practices, and techniques, as well as a range of different technologies
  • Create websites and data services capable of massive scaling using Go’s net/http package,
  • Explore RESTful patterns as well as low-latency WebSocket APIs
  • Interact with a variety of remote web services to consume capabilities, ranging from authentication and authorization to a fully functioning thesaurus

Authors

Table of Contents

Chapter 1: A First Step in Go
The Go programming language
Playing with Go
Your first Go program
Go in a nutshell
Summary
Chapter 2: Go Language Essentials
The Go source file
Go identifiers
Go variables
Go constants
Go operators
Summary
Chapter 3: Go Control Flow
The if statement
Switch statements
The for statements
The break, continue, and goto statements
Summary
Chapter 4: Data Types
Go types
Numeric types
Boolean type
Rune and string types
Pointers
Type declaration
Type conversion
Summary
Chapter 5: Functions in Go
Go functions
Passing parameter values
Higher-order functions
Error signaling and handling
Deferring function calls
Function panic and recovery
Summary
Chapter 6: Go Packages and Programs
The Go package
Creating packages
Building packages
Package visibility
Importing package
Package initialization
Creating programs
Remote packages
Summary
Chapter 7: Composite Types
The array type
The slice type
The map type
The struct type
Summary
Chapter 8: Methods, Interfaces, and Objects
Go methods
Objects in Go
The interface type
Type assertion
Summary
Chapter 9: Concurrency
Goroutines
Channels
Writing concurrent programs
The sync package
Detecting race conditions
Parallelism in Go
Summary
Chapter 10: Data IO in Go
IO with readers and writers
The io.Reader interface
The io.Writer interface
Working with the io package
Working with files
Formatted IO with fmt
Buffered IO
In-memory IO
Encoding and decoding data
Summary
Chapter 11: Writing Networked Services
The net package
A TCP API server
The HTTP package
A JSON API server
Summary
Chapter 12: Code Testing
The Go test tool
Writing Go tests
HTTP testing
Test coverage
Code benchmark
Summary
Chapter 13: Ready... Steady... Go!
A little bit of history
Installing Go
Starting with Hello World
Integrated Development Environment - IDE
Types
Variables and constants
Operators
Flow control
Functions
Arrays, slices, and maps
Visibility
Zero-initialization
Pointers and structures
Interfaces
Testing and TDD
Libraries
The Go get tool
Managing JSON data
Go tools
Contributing to Go open source projects in GitHub
Summary
Chapter 14: Creational Patterns - Singleton, Builder, Factory, Prototype, and Abstract Factory Design Patterns
Singleton design pattern - having a unique instance of a type in the entire program
Builder design pattern - reusing an algorithm to create many implementations of an interface
Factory method - delegating the creation of different types of payments
Abstract Factory - a factory of factories
Prototype design pattern
Summary
Chapter 15: Structural Patterns - Composite, Adapter, and Bridge Design Patterns
Composite design pattern
Adapter design pattern
Bridge design pattern
Summary
Chapter 16: Structural Patterns - Proxy, Facade, Decorator, and Flyweight Design Patterns
Proxy design pattern
Decorator design pattern
Facade design pattern
Flyweight design pattern
Summary
Chapter 17: Behavioral Patterns - Strategy, Chain of Responsibility, and Command Design Patterns
Strategy design pattern
Chain of responsibility design pattern
Command design pattern
Summary
Chapter 18: Behavioral Patterns - Template, Memento, and Interpreter Design Patterns
Template design pattern
Memento design pattern
Interpreter design pattern
Summary
Chapter 19: Behavioral Patterns - Visitor, State, Mediator, and Observer Design Patterns
Visitor design pattern
State design pattern
Mediator design pattern
Observer design pattern
Chapter 20: Introduction to Gos Concurrency
A little bit of history and theory
Goroutines
Callbacks
Mutexes
Channels
Using it all - concurrent singleton
Summary
Chapter 21: Concurrency Patterns - Barrier, Future, and Pipeline Design Patterns
Barrier concurrency pattern
Future design pattern
Pipeline design pattern
Summary
Chapter 22: Concurrency Patterns - Workers Pool and Publish/Subscriber Design Patterns
Workers pool
Concurrent Publish/Subscriber design pattern
Summary
Chapter 23: Chat Application with Web Sockets
A simple web server
Modeling a chat room and clients on the server
Building an HTML and JavaScript chat client
Tracing code to get a look under the hood
Summary
Chapter 24: Adding User Accounts
Handlers all the way down
Making a pretty social sign-in page
Endpoints with dynamic paths
Getting started with OAuth2
Tell the authorization providers about your app
Implementing external logging in
Summary
Chapter 25: Three Ways to Implement Profile Pictures
Avatars from the OAuth2 server
Implementing Gravatar
Uploading an avatar picture
Combining all three implementations
Summary
Chapter 26: Command-Line Tools to Find Domain Names
Pipe design for command-line tools
Five simple programs
Composing all five programs
Summary
Chapter 27: Building Distributed Systems and Working with Flexible Data
The system design
Installing the environment
Reading votes from Twitter
Counting votes
Running our solution
Summary
Chapter 28: Exposing Data and Functionality through a RESTful Data Web Service API
RESTful API design
Sharing data between handlers
Wrapping handler functions
Injecting dependencies
Responding
Understanding the request
Serving our API with one function
Handling endpoints
A web client that consumes the API
Running the solution
Summary
Chapter 29: Random Recommendations Web Service
The project overview
Representing data in code
Generating random recommendations
Summary
Chapter 30: Filesystem Backup
Solution design
The backup package
The user command-line tool
The daemon backup tool
Testing our solution
Summary
Chapter 31: Building a Q&A Application for Google App Engine
The Google App Engine SDK for Go
Google Cloud Datastore
Entities and data access
Google App Engine users
Transactions in Google Cloud Datastore
Querying in Google Cloud Datastore
Votes
Casting a vote
Exposing data operations over HTTP
Running apps with multiple modules
Deploying apps with multiple modules
Summary
Chapter 32: Micro-services in Go with the Go kit Framework
Introducing gRPC
Protocol buffers
Building the service
Modeling method calls with requests and responses
An HTTP server in Go kit
A gRPC server in Go kit
Creating a server command
Building a gRPC client
Rate limiting with service middleware
Summary
Chapter 33: Deploying Go Applications Using Docker
Using Docker locally
Deploying Docker images
Deploying to Digital Ocean
Summary

Book Details

ISBN 139781788390552
Paperback1091 pages
Read More
From 4 reviews

Read More Reviews

Recommended for You

Go: Building 7 Real-World Projects Book Cover
Go: Building 7 Real-World Projects
$ 124.99
$ 106.25
Spring MVC: Designing Real-World Web Applications Book Cover
Spring MVC: Designing Real-World Web Applications
$ 69.99
$ 49.00
Learn MeteorJS By Building 10 Real World Projects [Video] Book Cover
Learn MeteorJS By Building 10 Real World Projects [Video]
$ 98.99
$ 84.15
Hadoop Real-World Solutions Cookbook Book Cover
Hadoop Real-World Solutions Cookbook
$ 29.99
$ 21.00
JavaScript Design Patterns 20 Patterns for Advancing Your JavaScript Skills [Video] Book Cover
JavaScript Design Patterns 20 Patterns for Advancing Your JavaScript Skills [Video]
$ 94.99
$ 80.75
React Design Patterns for Beginners [Video] Book Cover
React Design Patterns for Beginners [Video]
$ 124.99
$ 106.25