Go Web Programming
eBook - ePub

Go Web Programming

Sau Sheong Chang

  1. 312 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Go Web Programming

Sau Sheong Chang

Book details
Book preview
Table of contents
Citations

About This Book

Summary Go Web Programming teaches you how to build scalable, high-performance web applications in Go using modern design principles.Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the Technology The Go language handles the demands of scalable, high-performance web applications by providing clean and fast compiled code, garbage collection, a simple concurrency model, and a fantastic standard library. It's perfect for writing microservices or building scalable, maintainable systems. About the Book Go Web Programming teaches you how to build web applications in Go using modern design principles. You'll learn how to implement the dependency injection design pattern for writing test doubles, use concurrency in web applications, and create and consume JSON and XML in web services. Along the way, you'll discover how to minimize your dependence on external frameworks, and you'll pick up valuable productivity techniques for testing and deploying your applications. What's Inside

  • Basics
  • Testing and benchmarking
  • Using concurrency
  • Deploying to standalone servers, PaaS, and Docker
  • Dozens of tips, tricks, and techniques


About the Reader This book assumes you're familiar with Go language basics and the general concepts of web development. About the Author Sau Sheong Chang is Managing Director of Digital Technology at Singapore Power and an active contributor to the Ruby and Go communities. Table of Contents

PART 1 GO AND WEB APPLICATIONS

  • Go and web applications
  • Go ChitChat

PART 2 BASIC WEB APPLICATIONS

  • Handling requests
  • Processing requests
  • Displaying content
  • Storing data

PART 3 BEING REAL

  • Go web services
  • Testing your application
  • Leveraging Go concurrency
  • Deploying Go

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Go Web Programming an online PDF/ePUB?
Yes, you can access Go Web Programming by Sau Sheong Chang in PDF and/or ePUB format, as well as other popular books in Computer Science & Web Services & APIs. We have over one million books available in our catalogue for you to explore.

Information

Publisher
Manning
Year
2016
ISBN
9781638353409

Part 1. Go and web applications

Web applications are probably the most widely used type of software application today and if you’re connected to the internet, you would hardly pass a day without using one. Even if you’re mostly on a mobile device, you still are using web applications. Many mobile applications that look like native applications are hybrids that have portions that built on web technologies.
Knowing HTTP is the foundation to learning how to write web applications, so these first two chapters will introduce HTTP. I will also explain why using Go for writing web applications is a good idea. I will jump straight into showing you how to write a simple internet forum using Go and show you a bird’s-eye view of writing a web application.

Chapter 1. Go and web applications

This chapter covers
  • Defining web applications
  • Using Go to write web applications: the advantages
  • Understanding the basics of web application programming
  • Writing the simplest possible web application in Go
Web applications are ubiquitous. Take any application you use on a daily basis, and likely it’s a web application or has a web application variant (this includes mobile apps). Any language that supports software development that interfaces with human beings will inevitably support web application development. One of the first things developers of a new language do is build libraries and frameworks to interact with the internet and the World Wide Web. There are myriad web development tools for the more established languages.
Go is no different. Go is a relatively new programming language created to be simple and efficient for writing back end systems. It has an advanced set of features and focuses on programmer effectiveness and speed. Since its release, Go has gained tremendous popularity as a programming language for writing web applications and *-as-a-Service systems.
In this chapter, you’ll learn why you should use Go for writing web applications and you’ll learn all about web applications.

1.1. Using Go for web applications

So why should you use Go for writing web applications? My guess is, having bought this book, you have an inclination to find out the answer. Of course, as the author of a book that teaches Go web programming, I believe there are strong and compelling reasons to do so. As you continue reading this book, you’ll get a sense of Go’s strengths in web application development and, I hope, agree with me about the usefulness of Go.
Go is a relatively new programming language, with a thriving and growing community. It is well suited for writing server-side programs that are fast. It’s simple and familiar to most programmers who are used to procedural programming, but it also provides features of functional programming. It supports concurrency by default, has a modern packaging system, does garbage collection, and has an extensive and powerful set of built-in standard libraries.
Plenty of good-quality open source libraries are available that can supplement what the standard libraries don’t have, but the standard libraries that come with Go are quite comprehensive and wide-ranging. This book sticks to the standard libraries as much as possible but will occasionally use third-party, open source libraries to show alternative and creative ways the open source community has come up with.
Go is rapidly gaining popularity as a web development language. Many companies, including infrastructure companies like Dropbox and SendGrid, technology-oriented companies such as Square and Hailo, as well as more traditional companies such as BBC and The New York Times, have already started using Go.
Go provides a viable alternative to existing languages and platforms for developing large-scale web applications. Large-scale web applications typically need to be
  • Scalable
  • Modular
  • Maintainable
  • High-performance
Let’s take a look at these attributes in detail.

1.1.1. Scalable web applications and Go

Large-scale web applications should be scalable. This means you should be able to quickly and easily increase the capacity of the application to take on a bigger volume of requests. The application should scale also linearly, meaning you should be able to add more hardware and process a corresponding number of requests.
We can look at scaling in two ways:
  • Vertical scaling, or increasing the amount of CPUs or capacity in a single machine
  • Horizontal scaling, or increasing the number of machines to expand capacity
Go scales well vertically with its excellent support for concurrent programming. A single Go web application with a single OS thread can be scheduled to run hundreds of thousands of goroutines with efficiency and performance.
Just like any other web applications, Go can scale well horizontally as well as by layering a proxy above a number of instances of a Go web app. Go web applications are compiled as static binaries, without any dynamic dependencies, and can be distributed to systems that don’t have Go built in. This allows you to deploy Go web applications easily and consistently.

1.1.2. Modular web applications and Go

Large-scale web applications should be built with components that work interchangeably. This approach allows you to add, remove, or modify features easily and gives you the flexibility to meet the changing needs of the application. It also allows you to lower software development costs by reusing modular components.
Although Go is statically typed, it has an interface mechanism that describes behavior and allows dynamic typing. Functions can take interfaces, which means you can introduce new code into the system and still be able to use existing functions by implementing methods required by that interface. Also, with a function that takes an empty interface, you can put any value as the parameter because all types implement the empty interface. Go implements a number of features usually associated with functional programming, including function types, functions as values, and closures. These features allow you to build more modular code by providing the capability of building functions out of other functions.
Go is also often used to create microservices. In microservice architecture large-scale applications can be created by composing smaller independent services. These services are interchangeable and organized around capabilities (for example, a systems-level service like logging or an application-level service such as billing or risk analysis). By creating multiple small Go services and composing them into a single web application, you enable these capabilities to be swappable and therefore more modular.

1.1.3. Maintainable web applications and Go

Like any large and complex applications, having an easily maintainable codebase is important for large-scale web applications. It’s important because large-scale applications often need to grow and evolve and therefore you need to revisit and change the code regularly. Complex, unwieldy code takes a long time to change and is fraught with risk of something breaking, so it makes sense to keep the source code well organized and maintainable.
Go was designed to encourage good software engineering practices. It has a clean and simple syntax that’s very readable. Go’s package system is flexible and unambiguous, and there’s a good set of tools to enhance the development experience and help programmers to write more readable code. An example is the Go sourc...

Table of contents

  1. Copyright
  2. Brief Table of Contents
  3. Table of Contents
  4. Preface
  5. Acknowledgments
  6. About this Book
  7. About the Cover Illustration
  8. Part 1. Go and web applications
  9. Part 2. Basic web applications
  10. Part 3. Being real
  11. Appendix. Installing and setting up Go
  12. Index
  13. List of Figures
  14. List of Tables
  15. List of Listings