Go in Practice
eBook - ePub

Go in Practice

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

Go in Practice

Book details
Book preview
Table of contents
Citations

About This Book

Summary Go in Practice guides you through 70 real-world techniques in key areas like package management, microservice communication, and more. Following a cookbook-style Problem/Solution/Discussion format, this practical handbook builds on the foundational concepts of the Go language and introduces specific strategies you can use in your day-to-day applications.Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the Technology Go may be the perfect systems language. Built with simplicity, concurrency, and modern applications in mind, Go provides the core tool set for rapidly building web, cloud, and systems applications. If you know a language like Java or C#, it's easy to get started with Go; the trick is finding the practical dirt-under-the-fingernails techniques that you need to build production-ready code. About the Book Go in Practice guides you through dozens of real-world techniques in key areas. Following a cookbook-style Problem/Solution/Discussion format, this practical handbook builds on the foundational concepts of the Go language and introduces specific strategies you can use in your day-to-day applications. You'll learn techniques for building web services, using Go in the cloud, testing and debugging, routing, network applications, and much more. After finishing this book, you will be ready to build sophisticated cloud-native Go applications. What's Inside

  • Dozens of specific, practical Golang techniques
  • Using Go for devops and cloudops
  • Writing RESTful web services and microservices
  • Practical web dev techniques


About the Reader Written for experienced developers who have already started exploring Go and want to use it effectively in a production setting. About the Authors Matt Farina is a software architect at Deis. Matt Butcher is a Principal Engineer in the Advanced Technology Group at Hewlett Packard Enterprise. They are both authors, speakers, and regular open source contributors. Table of Contents

PART 1 - BACKGROUND AND FUNDAMENTALS

  • Getting into Go
  • A solid foundation
  • Concurrency in Go

PART 2 - WELL-ROUNDED APPLICATIONS

  • Handling errors and panic
  • Debugging and testing

PART 3 - AN INTERFACE FOR YOUR APPLICATIONS

  • HTML and email template patterns
  • Serving and receiving assets and forms
  • Working with web services

PART 4 - TAKING YOUR APPLICATIONS TO THE CLOUD

  • Using the cloud
  • Communication between cloud services
  • Reflection and code generation

Frequently asked questions

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.
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.
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.
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.
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.
Yes, you can access Go in Practice by Matt Farina, Matt Butcher in PDF and/or ePUB format, as well as other popular books in Informatik & Programmiersprachen. We have over one million books available in our catalogue for you to explore.

Information

Publisher
Manning
Year
2016
ISBN
9781638356813

Part 1. Background and fundamentals

This opening part of the book provides some background about Go and a foundation for building applications. Chapter 1 starts with an overview of Go for those not already familiar with it.
Chapters 2 and 3 move into base components for an application. Chapter 2 provides the foundation for building an application, including working with console applications and servers, and handling configuration. Chapter 3 focuses on using goroutines. Goroutines are one of the more powerful and useful elements in Go. They’re regularly used in Go applications, and you’ll see them through the rest of this book.

Chapter 1. Getting into Go

This chapter covers
  • Introducing Go
  • Understanding where Go fits into the language landscape
  • Getting up and running in Go
The way we build and run software is changing. Innovation has swept in, disrupting long-standing assumptions about the computing environments that software runs in. To fully take advantage of these innovations, you need languages and tools that support them at their core.
When most mainstream programming languages and supporting toolchains were developed, they were designed for single-core processing. That’s what we had. Now desktop computers, servers, and even our phones have processors with multiple cores. Running software with operations taking place concurrently can happen anywhere.
Toolchains around building applications have changed. Increased functionality and complexity in software requires environments that can build and execute the code rapidly and efficiently. Testing larger and more complicated codebases needs to happen quickly so it doesn’t become a development blocker. Many applications are developed using libraries. Libraries and their versions are managed differently, thanks to solutions to disk-space problems that hampered this in the past.
The way infrastructure and software are delivered has changed. Using colocated servers, managing your own hardware, or getting simple virtual private servers used to be the norm. Standing up a service at scale often meant you needed an investment in running your own hardware, including load balancers, servers, and storage. Getting everything ordered, assembled, and connected to the world would take weeks or months. Now it’s available in a matter of seconds or minutes via the cloud.
This chapter introduces the Go programming language for those not already familiar with it. In this chapter, you’ll learn about the language, the toolchain that accompanies it, where Go fits into the landscape of languages, and how to install Go and get it running.

1.1. What is Go?

Go, sometimes referred to as golang to make it easier to find on the web, is a statically typed and compiled open source programming language initially developed by Google. Robert Griesemer, Rob Pike, and Ken Thompson were attempting to create a language for modern systems programming that solved real-world problems they encountered while building large systems at scale.
Instead of attempting to attain theoretical pureness, these designers engineered Go around real-world practical situations. It’s inspired by a host of languages that came before it, including C, Pascal, Smalltalk, Newsqueak, C#, JavaScript, Python, Java, and many others.
Go isn’t the typical statically typed and compiled language. The static typing has features that make it feel dynamic, and the compiled binaries have a runtime that includes garbage collection. The design of the language took into account the types of projects that Google would need to use it for: large codebases operating at scale and being developed by large developer teams.
At its core, Go is a programming language defined by a specification that can be implemented by any compiler. The default implementation is shipped via the go tool. But Go is more than a programming language. As figure 1.1 illustrates, layers are built on top of the language.
Figure 1.1. The layers of Go
Developing applications requires more than a programming language—for example, testing, documentation, and formatting. Each of these areas needs tools to support it. The go tool that’s used to compile applications also provides functionality to support these elements. It’s a toolchain for application development. One of the most notable aspects of the toolchain is package management. Out of the box, the programming language Go and the go toolchain provide for packages. A built-in package system, along with a common toolchain for the essential elements of development, has enabled an ecosystem to form around the programming language.
One of the defining characteristics of Go is its simplicity. When Griesemer, Pike, and Thompson were originally designing the language, a feature didn’t go in until all three agreed that it should be a feature of the language. This style of decision-making, along with their years of experience, led to a simple but powerful language. It’s simple enough to keep in your head yet powerful enough to write a wide variety of software.
An example of this philosophy can be seen in the variable syntax:
var i int = 2
Here a variable is created as an integer and set to a value of 2. Because an initial value is given, you can shorten the syntax as follows:
var i = 2
When an initial value is provided, the compiler is smart enough to figure out the type. In this case, the compiler sees the value of 2 and knows the type is an integer.
Go doesn’t stop there. Do we need the var keyword? Go provides something called short variable declarations:
i := 2
This is a concise equivalent to the first variable statement. It’s less than half the length of the first example, easy to read, and happens because the compiler figures out the missing parts.
Simplicity means Go doesn’t have all the features of every other programming language. For example, Go has neither a ternary operator (usually ?:) nor type generics. Lacking some features present in other modern languages has opened Go to occasional c...

Table of contents

  1. Copyright
  2. Brief Table of Contents
  3. Table of Contents
  4. Foreword
  5. Preface
  6. Acknowledgments
  7. About this Book
  8. About the Authors
  9. About the Cover Illustration
  10. Part 1. Background and fundamentals
  11. Part 2. Well-rounded applications
  12. Part 3. An interface for your applications
  13. Part 4. Taking your applications to the cloud
  14. Index
  15. List of Figures
  16. List of Listings