Level Up Your Web Apps With Go
Table of Contents
Preface
Who Should Read This Book
Conventions Used
Code Samples
Tips, Notes, and Warnings
Supplementary Materials
Some Notes
HTTP Requests
Go Get
Formatting
Imports
Guiding Gently, Not Explicitly
Terminal
Want to take your learning further?
Welcome New Gopher
Installation
The Go Workspace
Mac OS and Linux
Windows
Your First Go Code
Go Tools
Basic Types
Strings
Numbers
Integers
Floats
Booleans
Arrays and Slices
Looping
Maps
Looping over Maps
Dealing with Map Values
Functions
Pointers
Structs
Type Methods
Exported and Unexported Code
Summary
Go Types Explored
Custom Types
Interfaces
Error Handling
Embedded Types
The defer Command
Third-party Libraries
Syntax Options and Conventions
Alternative Syntax Options
Initializing Structs without Field Names
Empty Variable Initialization
Trailing Commas
Coding Style Conventions
Variable Naming
Constants
Constructors
Summary
HTTP
Responding to Requests
Breaking It Down
Adding More Information
Pattern Matching in Depth
Returning Errors
The Handler Interface
Chaining Handlers to Create Middleware
HTML Templates
Accessing Data
Conditionals with if and else
Loops with Range
Multiple Templates
Pipelines
Variables
Rendering JSON
Marshaling
Marshaling Structs
Custom JSON Keys
Nested Types
Unmarshaling Types
Unknown JSON Structure
Summary
Gophr Part 1: The Project
Using Bootstrap
Project Layout
Serving Assets
Rendering Pages
Creating a Layout
Advanced Routing
Using httprouter
Flexible Middleware
How Routing Works with Our Middleware
Summary
Gophr Part 2: All About the Users
Before We Start
What do users look like?
Hashing a Password
Identifiers
User Forms
Creating Users
Registration Form
Registration Handler
Creating Users
Input Validation
Persisting Users
Summary
Exercises
Gophr Part 3: Remembering Our Users
What makes up a session?
Persisting User Sessions
Checking for a User
Displaying User Information
Signing Out, Signing In
The Sign Out Process
The Login Process
Editing Your Details
Summary
Exercises
Gophr Part 4: Images
The Image Type
ImageStore Interface
Getting My(SQL) Groove On
MySQL Requirements
Connecting to Databases
Creating ImageStore
Implementing ImageStore in DBImageStore
Save
Find
FindAll
FindAllByUser
Uploading Images
Creating Images from a URL
Creating Images from a File
Displaying Images
Showing the Front Page Images
Showing a Single Image
Showing a User’s Images Only
Summary
Exercises
Gophr Part 5: Concurrency
Goroutines
Waiting for Goroutines to Finish
Communicating with Goroutines
Communicating with Multiple Channels
Using Channels and Selects for Timeouts
Looping on selects
Throwing Away Goroutines
Putting Goroutines into Practice
Using the Resized Images
Summary
Automated Testing
Writing Tests in Go
Passing and Failing
Testing Multiple Variations of Inputs
Code Coverage
Testing Between Packages
Testing HTTP Requests and Responses
Testing the Gophr Authentication
Testing Remote HTTP requests
Performance Benchmarking
Benchmark Regressions
Summary
Exercises
Packaging and Production
Creating Packages
What is a package?
An Example Package
Exporting
Avoiding Circular Imports
Let’s Implement a Real Package
Package Exercise
Dependency Management
Godep
Saving Your Dependencies
Using Dependencies
The gopkg.in Service
Deploying Go Applications
Compiling on the Server
Compiling Elsewhere
Cross-compiling
Building Go for Other Platforms
Mac OS and Linux
Windows
Building Binaries for Other Platforms
That’s All, Folks!