Go: Building Web Applications
eBook - ePub

Go: Building Web Applications

Nathan Kozyra, Mat Ryer

Buch teilen
  1. 665 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Go: Building Web Applications

Nathan Kozyra, Mat Ryer

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

Build real-world, production-ready solutions by harnessing the powerful features of Go

About This Book

  • An easy-to-follow guide that provides everything a developer needs to know to build end-to-end web applications in Go
  • Write interesting and clever, but simple code, and learn skills and techniques that are directly transferable to your own projects
  • A practical approach to utilize application scaffolding to design highly scalable programs that are deeply rooted in go routines and channels

Who This Book Is For

This book is intended for developers who are new to Go, but have previous experience of building web applications and APIs.

What You Will Learn

  • Build a fully featured REST API to enable client-side single page apps
  • Utilize TLS to build reliable and secure sites
  • Learn to apply the nuances of the Go language to implement a wide range of start-up quality projects
  • Create websites and data services capable of massive scale using Go's net/http package, exploring 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
  • Explore the core syntaxes and language features that enable concurrency in Go
  • Understand when and where to use concurrency to keep data consistent and applications non-blocking, responsive, and reliable
  • Utilize advanced concurrency patterns and best practices to stay low-level without compromising the simplicity of Go itself

In Detail

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software. It is a statically typed language with syntax loosely derived from that of C, adding garbage collection, type safety, some dynamic-typing capabilities, additional built-in types such as variable-length arrays and key-value maps, and a large standard library.

This course starts with a walkthrough of the topics most critical to anyone building a new web application. Whether it's keeping your application secure, connecting to your database, enabling token-based authentication, or utilizing logic-less templates, this course has you covered.

Scale, performance, and high availability lie at the heart of the projects, and the lessons learned throughout this course will arm you with everything you need to build world-class solutions. It will also take you through the history of concurrency, how Go utilizes it, how Go differs from other languages, and the features and structures of Go's concurrency core. It will make you feel comfortable designing a safe, data-consistent, and high-performance concurrent application in Go.

This course is an invaluable resource to help you understand Go's powerful features to build simple, reliable, secure, and efficient web applications.

Style and approach

This course is a step-by-step guide, which starts off with the basics of go programming to build web applications and will gradually move on to cover intermediate and advanced topics. You will be going through this smooth transition by building interesting projects along with the authors, discussing significant options, and decisions at each stage, while keeping the programs lean, uncluttered, and as simple as possible.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Go: Building Web Applications als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Go: Building Web Applications von Nathan Kozyra, Mat Ryer im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Web Programming. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2016
ISBN
9781787123496

Go: Building Web Applications


Table of Contents

Go: Building Web Applications
Go: Building Web Applications
Credits
Preface
What this learning path covers
What you need for this learning path
Who this learning path is for
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Module 1
1. Introducing and Setting Up Go
Installing Go
Structuring a project
Code conventions
Importing packages
Handling private repositories
Dealing with versioning
Introducing the net package
Hello, Web
Summary
2. Serving and Routing
Serving files directly
Basic routing
Using more complex routing with Gorilla
Redirecting requests
Serving basic errors
Summary
3. Connecting to Data
Connecting to a database
Creating a MySQL database
Using GUID for prettier URLs
Handling 404s
Summary
4. Using Templates
Introducing templates, context, and visibility
HTML templates and text templates
Displaying variables and security
Using logic and control structures
Summary
5. Frontend Integration with RESTful APIs
Setting up the basic API endpoint
RESTful architecture and best practices
Creating our first API endpoint
Implementing security
Creating data with POST
Modifying data with PUT
Summary
6. Sessions and Cookies
Setting cookies
Capturing user information
Creating users
Enabling sessions
Letting users register
Letting users log in
Initiating a server-side session
Creating a store
Utilizing flash messages
Summary
7. Microservices and Communication
Introducing the microservice approach
Pros and cons of utilizing microservices
Understanding the heart of microservices
Communicating between microservices
Putting a message on the wire
Reading from another service
Summary
8. Logging and Testing
Introducing logging in Go
Logging to IO
Multiple loggers
Formatting your output
Using panics and fatal errors
Introducing testing in Go
Summary
9. Security
HTTPS everywhere – implementing TLS
Preventing SQL injection
Protecting against XSS
Preventing cross-site request forgery (CSRF)
Securing cookies
Using the secure middleware
Summary
10. Caching, Proxies and Improved Performance
Identifying bottlenecks
Implementing reverse proxies
Implementing caching strategies
Using Least Recently Used
Caching by file
Caching in memory
Implementing HTTP/2
Summary
2. Module 2
1. Chat Application with Web Sockets
A simple web server
Templates
Doing things once
Using your own handlers
Properly building and executing Go programs
Modeling a chat room and clients on the server
Modeling the client
Modeling a room
Concurrency programming using idiomatic Go
Turning a room into an HTTP handler
Use helper functions to remove complexity
Creating and using rooms
Building an HTML and JavaScript chat client
Getting more out of templates
Tracing code to get a look under the hood
Writing a package using TDD
Interfaces
Unit tests
Red-green testing
Implementing the interface
Unexported types being returned to users
Using our new trace package
Making tracing optional
Clean package APIs
Summary
2. Adding Authentication
Handlers all the way down
Making a pretty social sign-in page
Endpoints with dynamic paths
OAuth2
Open source OAuth2 packages
Tell the authentication providers about your app
Implementing external logging in
Logging in
Handling the response from the provider
Presenting the user data
Augmenting messages with additional data
Summary
3. Three Ways to Implement Profile Pictures
Avatars from the authentication server
Getting the avatar URL
Transmitting the avatar URL
Adding the avatar to the user interface
Logging out
Making things prettier
Implementing Gravatar
Abstracting the avatar URL process
The authentication service and avatar's implementation
Using an implementation
Gravatar implementation
Uploading an avatar picture
User identification
An upload form
Handling the upload
Serving the images
The Avatar implementation for local files
Supporting different file types
Refactoring and optimizing our code
Replacing concrete types with interfaces
Changing interfaces in a test-driven way
Fixing existing implementations
Global variables versus fields
Implementing our new design
Tidying up and testing
Combining all three implementations
Summary
4. Command-line Tools to Find Domain Names
Pipe design for command-line tools
Five simple programs
Sprinkle
Exercise – configurable transformations
Domainify
Exercise – making top-level domains configurable
Coolify
Synonyms
Using environment variables for configuration
Consuming a web API
Getting domain suggestions
Available
Composing all five programs
One program to rule them all
Summary
5. Building Distributed Systems and Working with Flexible Data
System design
Database design
Installing the environment
NSQ
NSQ driver for Go
MongoDB
MongoDB driver for Go
Starting the environment
Votes from Twitter
Authorization with Twitter
Extracting the connection
Reading environment variables
Reading from MongoDB
Reading from Twitter
Signal channels
Publishing to NSQ
Gracefully starting and stopping
Testing
Counting votes
Connecting to the database
Consuming messages in NSQ
Keeping the database updated
Responding to Ctrl + C
Running our solution
Summary
6. Exposing Data and Functionality through a RESTful Data Web Service API
RESTful API design
Sharing data between handlers
Wrapping handler functions
API key
Database session
Per request variables
Cross-browser resource sharing
Responding
Understanding the request
A simple main function to serve our API
Using handler function wrappers
Handling endpoints
Using tags to add metadata to structs
Many operations with a single handler
Reading polls
Creating a poll
Deleting a poll
CORS support
Testing our API using curl
A web client that consumes the API
An index page showing a list of polls
A page to create a new poll
A page to show details of the poll
Running the solution
Summary
7. Random Recommendations Web Service
Project overview
Project design specifics
Representing data in code
Public views of Go structs
Generating random recommendations
Google Places API key
Enumerators in Go
Test-driven enumerator
Querying the Google Places API
Building recommendations
Handlers that use query parameters
CORS
Testing our API
Web application
Summary
8. Filesystem Backup
Solution design
Project structure
Backup package
Obvious interfaces?
Implementing ZIP
Has the filesystem changed?
Checking for changes and initiating a backup
Hardcoding is OK for a short while
The user command-line tool
Persisting small data
Parsing arguments
Listing the paths
String representations for your own types
Adding paths
Removing paths
Using our new tool
The daemon backup tool
Duplicated structures
Caching data
Infinite loops
Updating filedb records
Testing our solution
Summary
3. Module 3
1. An Introduction to Concurrency in Go
Introducing goroutines
A patient goroutine
Implementing the defer ...

Inhaltsverzeichnis