Book Image

Learning Go Web Development

By : Nathan Kozyra
Book Image

Learning Go Web Development

By: Nathan Kozyra

Overview of this book

<p>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.</p> <p>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.</p>
Table of Contents (17 chapters)
Learning Go Web Development
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Redirecting requests


Before we look at simple and incredibly common errors like 404s, let's address the idea of redirecting requests, something that's very common. Although not always for reasons that are evident or tangible for the average user.

So we might we want to redirect requests to another request? Well there are quite a few reasons, as defined by the HTTP specification that could lead us to implement automatic redirects on any given request. Here are a few of them with their corresponding HTTP status codes:

  • A non-canonical address may need to be redirected to the canonical one for SEO purposes or for changes in site architecture. This is handled by 301 Moved Permanently or 302 Found.

  • Redirecting after a successful or unsuccessful POST. This helps us to prevent re-POSTing of the same form data accidentally. Typically, this is defined by 307 Temporary Redirect.

  • The page is not necessarily missing, but it now lives in another location. This is handled by the status code 301 Moved Permanently...