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

Learning Go Web Development

Book Description

Build frontend-to-backend web applications using the best practices of a powerful, fast, and easy-to-deploy server language

About This Book

  • Build a fully-featured REST API to enable client-side single page apps
  • Utilize TLS to build reliable and secure sites
  • A quick guide that provides everything a developer needs to know to build end-to-end web applications in Go

Who This Book Is For

This book is intended for experienced programmers with minimal-to-moderate exposure to the Go language. If you have some fundamentals down, but are looking for more detail when it comes to using Go for the web, this is the book for you.

What You Will Learn

  • Create a listening web server
  • Route requests
  • Implement SSL/TLS
  • Use Go’s logic-less templates
  • Implement caching for maximum performance
  • Use sessions and cookies
  • Utilize security best practices to keep users and data safe
  • Connect to data sources
  • Create a RESTful API

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.

Learning Go Web Development is a start-to-finish 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 book has you covered. You’ll begin by learning about routing requests and implementing SSL. Moving on, you’ll get to know about practices to keep users’ data safe. By the end of the book, you will be able to build robust, secure, and fully-featured applications for the web.

Style and approach

This concise book demonstrates by doing. You’ll build a component every step of the way and in the end, will have a blogging platform that can be used for personal experimentation and augmented to be used in production.

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 code file.

Table of Contents

  1. Learning Go Web Development
    1. Table of Contents
    2. Learning Go Web Development
    3. Credits
    4. About the Author
    5. About the Reviewer
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Introducing and Setting Up Go
      1. Installing Go
      2. Structuring a project
        1. Code conventions
      3. Importing packages
        1. Handling private repositories
        2. Dealing with versioning
      4. Introducing the net package
      5. Hello, Web
      6. Summary
    9. 2. Serving and Routing
      1. Serving files directly
      2. Basic routing
      3. Using more complex routing with Gorilla
      4. Redirecting requests
      5. Serving basic errors
      6. Summary
    10. 3. Connecting to Data
      1. Connecting to a database
        1. Creating a MySQL database
      2. Using GUID for prettier URLs
      3. Handling 404s
      4. Summary
    11. 4. Using Templates
      1. Introducing templates, context, and visibility
      2. HTML templates and text templates
      3. Displaying variables and security
      4. Using logic and control structures
      5. Summary
    12. 5. Frontend Integration with RESTful APIs
      1. Setting up the basic API endpoint
      2. RESTful architecture and best practices
      3. Creating our first API endpoint
      4. Implementing security
      5. Creating data with POST
      6. Modifying data with PUT
      7. Summary
    13. 6. Sessions and Cookies
      1. Setting cookies
      2. Capturing user information
        1. Creating users
        2. Enabling sessions
        3. Letting users register
        4. Letting users log in
      3. Initiating a server-side session
        1. Creating a store
        2. Utilizing flash messages
      4. Summary
    14. 7. Microservices and Communication
      1. Introducing the microservice approach
      2. Pros and cons of utilizing microservices
      3. Understanding the heart of microservices
      4. Communicating between microservices
      5. Putting a message on the wire
      6. Reading from another service
      7. Summary
    15. 8. Logging and Testing
      1. Introducing logging in Go
      2. Logging to IO
        1. Multiple loggers
      3. Formatting your output
      4. Using panics and fatal errors
      5. Introducing testing in Go
      6. Summary
    16. 9. Security
      1. HTTPS everywhere – implementing TLS
      2. Preventing SQL injection
      3. Protecting against XSS
      4. Preventing cross-site request forgery (CSRF)
      5. Securing cookies
      6. Using the secure middleware
      7. Summary
    17. 10. Caching, Proxies and Improved Performance
      1. Identifying bottlenecks
      2. Implementing reverse proxies
      3. Implementing caching strategies
        1. Using Least Recently Used
        2. Caching by file
        3. Caching in memory
      4. Implementing HTTP/2
      5. Summary
    18. Index