O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Go Web Development Cookbook

Book Description

86 recipes on how to build fast, scalable, and powerful web services and applications with Go

About This Book
  • Become proficient in RESTful web services
  • Build scalable, high-performant web applications in Go
  • Get acquainted with Go frameworks for web development
Who This Book Is For

This book is for Go developers interested in learning how to use Go to build powerful web applications. A background in web development is expected.

What You Will Learn
  • Create a simple HTTP and TCP web server and understand how it works
  • Explore record in a MySQL and MongoDB database
  • Write and consume RESTful web service in Go
  • Invent microservices in Go using Micro – a microservice toolkit
  • Create and Deploy the Beego application with Nginx
  • Deploy Go web application and Docker containers on an AWS EC2 instance
In Detail

Go is an open source programming language that is designed to scale and support concurrency at the language level. This gives you the liberty to write large concurrent web applications with ease. From creating web application to deploying them on Amazon Cloud Services, this book will be your one-stop guide to learn web development in Go. The Go Web Development Cookbook teaches you how to create REST services, write microservices, and deploy Go Docker containers. Whether you are new to programming or a professional developer, this book will help get you up to speed with web development in Go. We will focus on writing modular code in Go; in-depth informative examples build the base, one step at a time. You will learn how to create a server, work with static files, SQL, NoSQL databases, and Beego. You will also learn how to create and secure REST services, and create and deploy Go web application and Go Docker containers on Amazon Cloud Services. By the end of the book, you will be able to apply the skills you've gained in Go to create and explore web applications in any domain.

Style and approach

This book helps you learn core Go concepts faster by taking a recipe-based approach.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Go Web Development Cookbook
  3. Dedication
  4. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  5. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Get in touch
      1. Reviews
  7. Creating Your First Server in Go
    1. Introduction
    2. Creating a simple HTTP server
      1. How to do it…
      2. How it works…
    3. Implementing basic authentication on a simple HTTP server
      1. Getting ready
      2. How to do it…
      3. How it works…
    4. Optimizing HTTP server responses with GZIP compression
      1. How to do it…
      2. How it works…
    5. Creating a simple TCP server
      1. How to do it…
      2. How it works…
    6. Reading data from a TCP connection
      1. Getting ready…
      2. How to do it…
      3. How it works…
    7. Writing data to a TCP connection
      1. Getting ready…
      2. How to do it…
      3. How it works…
    8. Implementing HTTP request routing
      1. How to do it…
      2. How it works…
    9. Implementing HTTP request routing using Gorilla Mux
      1. How to do it…
      2. How it works…
    10. Logging HTTP requests
      1. Getting Ready…
      2. How to do it…
      3. How it works…
  8. Working with Templates, Static Files, and HTML Forms
    1. Introduction
    2. Creating your first template
      1. How to do it…
      2. How it works…
    3. Serving static files over HTTP
      1. Getting ready…
      2. How to do it…
      3. How it works…
    4. Serving static files over HTTP using Gorilla Mux
      1. Getting ready…
      2. How to do it…
      3. How it works…
    5. Creating your first HTML form
      1. How to do it…
      2. How it works…
    6. Reading your first HTML form
      1. Getting ready…
      2. How to do it…
      3. How it works…
    7. Validating your first HTML form
      1. Getting ready…
      2. How to do it…
      3. How it works…
    8. Uploading your first file
      1. How to do it…
      2. How it works…
  9. Working with Sessions, Error Handling, and Caching in Go
    1. Introduction
    2. Creating your first HTTP session
      1. How to do it…
      2. How it works…
    3. Managing your HTTP session using Redis
      1. Getting ready…
      2. How to do it…
      3. How it works…
    4. Creating your first HTTP cookie
      1. How to do it…
      2. How it works…
    5. Implementing caching in Go
      1. How to do it…
      2. How it works…
    6. Implementing HTTP error handling in Go
      1. How to do it…
      2. How it works…
    7. Implementing login and logout in web application
      1. Getting ready…
      2. How to do it…
      3. How it works…
  10. Writing and Consuming RESTful Web Services in Go
    1. Introduction
    2. Creating your first HTTP GET method
      1. How to do it…
      2. How it works…
    3. Creating your first HTTP POST method
      1. How to do it…
      2. How it works…
    4. Creating your first HTTP PUT method
      1. How to do it…
      2. How it works…
    5. Creating your first HTTP DELETE method
      1. How to do it…
      2. How it works…
    6. Versioning your REST API
      1. How to do it…
      2. How it works…
    7. Creating your first REST client
      1. Getting ready…
      2. How to do it…
      3. How it works…
    8. Creating your first AngularJS Client
      1. Getting ready…
      2. How to do it…
      3. How it works…
    9. Creating your first ReactJS client
      1. Getting ready…
      2. How to do it…
      3. How it works…
    10. Creating your first VueJS client
      1. Getting ready…
      2. How to do it…
      3. How it works…
  11. Working with SQL and NoSQL Databases
    1. Introduction
    2. Integrating MySQL and Go
      1. Getting ready…
      2. How to do it…
      3. How it works…
    3. Creating your first record in MySQL
      1. Getting ready…
      2. How to do it…
      3. How it works…
    4. Reading records from MySQL
      1. How to do it…
      2. How it works…
    5. Updating your first record in MySQL
      1. How to do it…
      2. How it works…
    6. Deleting your first record from MySQL
      1. How to do it…
      2. How it works…
    7. Integrating MongoDB and Go
      1. Getting ready…
      2. How to do it…
      3. How it works…
    8. Creating your first document in MongoDB
      1. How to do it…
      2. How it works…
    9. Reading documents from MongoDB
      1. How to do it…
      2. How it works…
    10. Updating your first document in MongoDB
      1. How to do it…
      2. How it works…
    11. Deleting your first document from MongoDB
      1. How to do it…
      2. How it works…
  12. Writing Microservices in Go Using Micro – a Microservice Toolkit
    1. Introduction
    2. Creating your first protocol buffer
      1. Getting ready…
      2. How to do it…
      3. How it works…
    3. Spinning up a microservice discovery client
      1. Getting ready…
      2. How to do it…
      3. How it works…
    4. Creating your first microservice
      1. Getting ready…
      2. How to do it…
      3. How it works…
    5. Creating your second microservice
      1. How to do it…
      2. How it works…
    6. Creating your Micro API
      1. Getting ready…
      2. How to do it…
      3. How it works…
    7. Interacting with microservices using a command-line interface and web UI
      1. How to do it…
      2. How it works…
  13. Working with WebSocket in Go
    1. Introduction
    2. Creating your first WebSocket server
      1. How to do it…
      2. How it works…
    3. Creating your first WebSocket client
      1. How to do it…
      2. How it works…
    4. Debugging your first local WebSocket server
      1. Getting ready…
      2. How to do it…
      3. How it works…
    5. Debugging your first remote WebSocket server
      1. How to do it…
      2. How it works…
    6. Unit testing your first WebSocket server
      1. How to do it…
      2. How it works…
  14. Working with the Go Web Application Framework – Beego
    1. Introduction
    2. Creating your first project using Beego
      1. How to do it…
      2. How it works…
    3. Creating your first controller and router
      1. How to do it…
      2. How it works…
    4. Creating your first view
      1. How to do it…
      2. How it works…
    5. Creating your first session variable
      1. Getting ready…
      2. How to do it…
      3. How it works…
    6. Creating your first filter
      1. How to do it…
      2. How it works…
    7. Handling HTTP errors in Beego
      1. How to do it…
      2. How it works…
    8. Implementing caching in Beego
      1. How to do it…
      2. How it works…
    9. Monitoring the Beego application
      1. How to do it…
      2. How it works…
    10. Deploying the Beego application on a local machine
      1. How to do it…
      2. How it works…
    11. Deploying the Beego application with Nginx
      1. Getting ready…
      2. How to do it…
      3. How it works…
  15. Working with Go and Docker
    1. Introduction
    2. Building your first Go Docker image
      1. Getting ready…
      2. How to do it…
      3. How it works…
    3. Running your first Go Docker container
      1. How to do it…
      2. How it works…
    4. Pushing your Docker image to the Docker Registry
      1. How to do it…
      2. How it works…
    5. Creating your first user-defined bridge network
      1. How to do it…
      2. How it works…
    6. Running a MySQL Docker image on a user-defined bridge network
      1. How to do it…
      2. How it works…
    7. Building a Go web application Docker image
      1. How to do it…
      2. How it works…
    8. Running a web application Docker container linked with a MySQL Docker container on a user-defined bridge network
      1. How to do it…
      2. How it works…
  16. Securing a Go Web Application
    1. Introduction
    2. Creating a private key and SSL certificate using OpenSSL
      1. Getting ready…
      2. How to do it…
      3. How it works…
    3. Moving an HTTP server to HTTPS
      1. How to do it…
      2. How it works…
    4. Defining REST APIs and routes
      1. How to do it…
      2. How it works…
    5. Creating a JSON web token
      1. How to do it…
      2. How it works…
    6. Securing a RESTful service using a JSON web token
      1. How to do it…
      2. How it works…
    7. Preventing cross-site request forgery in Go web applications
      1. How to do it…
      2. How it works…
  17. Deploying a Go Web App and Docker Containers to AWS
    1. Introduction
    2. Creating your first EC2 instance to run a Go web application
      1. Getting ready…
      2. How to do it…
      3. How it works…
    3. Interacting with your first EC2 instance
      1. How to do it…
      2. How it works…
    4. Creating, copying, and running a Go web application on your first EC2 instance
      1. How to do it…
      2. How it works…
    5. Setting up an EC2 instance to run a Docker container
      1. How to do it…
      2. How it works…
    6. Pulling a Docker image on an AWS EC2 instance from Docker Hub
      1. How to do it…
      2. How it works…
    7. Running your Go Docker container on an EC2 instance
      1. How to do it…
      2. How it works…
  18. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think