Go Programming Blueprints
eBook - ePub

Go Programming Blueprints

Mat Ryer

Compartir libro
  1. 274 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Go Programming Blueprints

Mat Ryer

Detalles del libro
Vista previa del libro
Índice
Citas

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Go Programming Blueprints un PDF/ePUB en línea?
Sí, puedes acceder a Go Programming Blueprints de Mat Ryer en formato PDF o ePUB, así como a otros libros populares de Informatica y Sviluppo di applicazioni. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2015
ISBN
9781783988020

Go Programming Blueprints


Table of Contents

Go Programming Blueprints
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
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
A. Good Practices for a Stable Go Environment
Installing Go
Installing the C tools
Downloading and building Go from the source
Configuring Go
Getting GOPATH right
Go tools
Cleaning up, building, and running tests on save
Sublime Text 3
Summary
Index

Go Programming Blueprints

Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors, will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: January 2015
Production reference: 1200115
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78398-802-0
www.packtpub.com

Credits

Author
Mat Ryer
Reviewers
Tyler Bunnell
Michael Hamrah
Nimish Parmar
Commissioning Editor
Kunal Parikh
Acquisition Editor
Richard Brookes-Bland
Content Dev...

Índice