Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Go for DevOps
Go for DevOps

Go for DevOps : Learn how to use the Go language to automate servers, the cloud, Kubernetes, GitHub, Packer, and Terraform

Arrow left icon
Profile Icon John Doak Profile Icon David Justice
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (16 Ratings)
Paperback Jul 2022 634 pages 1st Edition
eBook
$44.99 $50.99
Paperback
$62.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon John Doak Profile Icon David Justice
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (16 Ratings)
Paperback Jul 2022 634 pages 1st Edition
eBook
$44.99 $50.99
Paperback
$62.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$44.99 $50.99
Paperback
$62.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Go for DevOps

Go Language Basics

DevOps is a concept that has been floating around since the early 2000s. It is a popularization of an operations discipline that relies on programming skills with development psychology popularized by Agile.

Site reliability engineering (SRE) is now considered a subdiscipline of DevOps, though it is likely the precursor to DevOps and relies more heavily on software skills and Service - Level Obligation (SLO)/Service - Level Agreement (SLA) modeling.

During my early time at Google, like many of today's DevOps shops, we used Python heavily. I think C++ was too painful for many SREs, and we had Python celebrities in Guido van Rossum and Alex Martelli.

But, as time wore on, many of the groups working in Python started having scaling issues. This included everything from Python running out of memory (requiring us to hack in our own malloc) to the Global Interpreter Lock (GIL) preventing us from true multithreading. At scale, we found that the lack of static types was giving us an abundance of errors that should have been caught at compile time. This mirrored what production services had seen years before.

But, Python came with more than compile-time and service-scaling issues. Simply moving to a new version of Python in the fleet might cause a service to stop working. The Python version run on Google machines would often get upgraded and expose bugs in your code that the previous version did not. Unlike a compiled binary, you could not just roll back to an old version.

Several of us in different organizations were looking to solve these types of problems without having to use C++. For my personal journey, I heard about Go from my colleagues in our Sydney office (Hey, Ross!). It was the pre-1.0 days, but they said it was already showing a lot of promise. I can't say I was even remotely convinced that what we needed was another language.

About 6 months later, however, I had bought Go hook, line, and sinker. It had everything we needed without everything we didn't. Now, it was still pre-1.0 days, so there was a certain amount of churn back then that was unpleasant (such as finding that Russ Cox had changed the time package over the weekend, so I had to rewrite a bunch of code). But, the benefits after writing my first service were undeniable.

I spent the next 4 years moving my department from a complete Python shop to almost a complete Go shop. I started teaching classes in Go across the world, targeted at operations engineers, rewriting core libraries for Go, and evangelizing to what was probably an annoying amount. Just because Go was invented at Google, it didn't mean that the engineers wanted to throw away their Python code and learn something new; there was more than a little resistance.

Now, Go has become the de facto language for cloud orchestration and software in the larger world (from Kubernetes to Docker). Go comes with all the tools you need to make huge strides in the reliability of your tooling and ability to scale.

Because many of these cloud services are written in Go, their parts are available to you by accessing their packages for your own tooling needs. This can make writing tooling for the cloud an easier experience.

For the next two chapters, I will be sharing my 10+ years' experience of teaching Go to engineers around the world to give you the basics and essentials of the Go language. Much of what you will read here is based on my free Go basics video training course, https://www.golangbasics.com. This course will differ slightly from that one in that it is more condensed. As you work your way through the book, we will continue to extend your knowledge of the Go language's standard library and third-party packages.

This chapter will cover the following main topics:

  • Using the Go Playground
  • Utilizing Go packages
  • Using Go's variable types
  • Looping in Go
  • Using conditionals
  • Learning about functions
  • Defining public and private
  • Using arrays and slices
  • Getting to know about structs
  • Understanding Go pointers
  • Comprehending Go interfaces

Now, let's get the basics down and get you on your way!

Technical requirements

The only technical requirement for this chapter is a modern web browser for using the Go Playground.

Using the Go Playground

The Go Playground, which you can find at https://play.golang.org/, is an online code editor and compiler that allows you to run Go code without installing Go on your machine. This is the perfect tool for our introductory chapters, allowing you to save your work online without the initial fuss of installing the Go tooling, or finding a code editor, for example.

There are four important parts of the Go Playground:

  • The code editing pane
  • The console window
  • The Run button
  • The Share button

The code editing pane, which is the yellow portion of the page, allows you to type in the Go code for your program. When you hit the Run button, the code will be compiled and then run with the output sent to the console, which is the white portion of the page below the code editor.

The following screen shows a glimpse of what the Go Playground does:

Figure 1.1 – Go Playground code editor

Figure 1.1 – Go Playground code editor

Clicking the Share button will store an immutable copy of the code and will change the URL from play.golang.org into a shareable link, such as play.golang.org/p/HmnNoBf0p1z. This link is a unique URL that you can bookmark and share with others. The code in this link cannot be changed, but if you hit the Share button again, it will create a new link with any changes.

Later chapters, starting with Chapter 4, Filesystem Interaction, will require installing the Go tooling for your platform.

This section taught you about the Go Playground and how to use it to write, view, share, and run your Go code. The Playground will be used extensively throughout the book to share runnable code examples.

Now, let's jump into writing Go code, starting with how Go defines packages.

Utilizing Go packages

Go provides reusable blocks of code that can be imported into other code using packages. Packages in Go are synonymous with libraries or modules in other languages. Packages are the building blocks of Go programs that divide the content into understandable parts.

This section will cover how to declare and import a package. We will discuss how to deal with package name conflicts, explore rules around packages, and we will write our first main package.

Declaring a package

Go divides programs into packages, sometimes called modules or libraries in other languages. Packages live on a path, and the path is made to look like a path to a directory on a Unix-like filesystem.

All Go files in a directory must belong to the same package. The package is most commonly named the same as the directory it lives in.

Declaring a package happens at the top of the file, and should only be preceded by a comment. Declaring a package is as simple as the following:

// Package main is the entrance point for our binary.
// The double slashes provides a comment until the end of the line.
/*
This is a comment that lasts until the closing star slash.
*/
package main

package main is special. All other package names declare a package that must be imported into another package to be used. package main will declare func main(), which is the starting point for a binary to run.

All Go files in a directory must have the same package header (compiler-enforced). These files, for most practical purposes, act as if they are concatenated together.

Let's say you have a directory structure as follows:

mypackage/
  file1.go
  file2.go

Then, file1.go and file2.go should have the following:

package mypackage

When mypackage is imported by another package, it will include everything declared in all files in the mypackage directory.

Importing a package

There are two general types of packages:

  • The standard library (stdlib) packages
  • All other packages

Standard library packages stand out because they don't list some repository information in their path, such as the following:

"fmt"
"encoding/json"
"archive/zip"

All other packages generally have repository information preceding them, as follows:

"github.com/johnsiilver/golib/lru"
"github.com/kylelemons/godebug/pretty"

Note

A complete listing of stdlib packages can be found at the following link: https://golang.org/pkg/.

To import packages, we use the import keyword. So, let's import the standard library fmt package and the mypackage package, which lives at github.com/devopsforgo/mypackage:

package main
import (
     "fmt"
     "github.com/devopsforgo/mypackage"
)

It is important to note that the filenames are not part of the package path, but simply the directory path.

Using a package

Once you've imported a package, you can start accessing functions, types, or variables declared in the package by prefacing what you want to access with the name of the package and a period.

For example, the fmt package has a function called Println() that can be used to print a line to stdout. If we want to use it, it is as simple as the following:

fmt.Println("Hello!")

Package name conflicts

Let's say you have two packages named mypackage. They both have the same name, so our program won't be able to tell which one we are referring to. You can rename a package import into whatever name you want:

import(
     "github.com/devopsforgo/mypackage"
     jpackage "github.com/johnsiilver/mypackage"
)

jpackage declares that in this package, we will refer to github.com/johnsiilver/mypackage as jpackage.

This ability allows us to use two similarly named packages as follows:

mypackage.Print()
jpackage.Send()

Now, we will look at an important rule around packages that improves compile-time and binary size.

Packages must be used

Let's introduce you to the following rule: If you import a package, you must use it.

One of the things that the Go authors noticed about many of the other programming languages being used at Google was that they often had unused imports.

This was leading to compile times that were longer than needed and, in some cases, binary sizes that were much bigger than required. Python files were packaged in a proprietary format to ship around production, and some of these unused imports were adding hundreds of megabytes to the files.

To prevent these types of problems, Go will not compile a program that imports a package but doesn't use it, as shown here:

package main
import (
     "fmt"
     "sync"
)
func main() {
     fmt.Println("Hello, playground")
}

The preceding code outputs the following:

./prog.go:5:2: imported and not used: "sync"

In certain rare circumstances, you may need to do a side effects import, in which just loading the package causes something to happen, but you don't use the package. This should always be done in package main and requires prepending with an underscore (_):

package main
import (
     "fmt"
     _ "sync" //Just an example 
)
func main() {
     fmt.Println("Hello, playground")
}

Next, we will declare a main package and discuss the basics of writing a Go program that imports a package.

A Go Hello World

Let's write a simple hello world program that is similar to the default program in the Go Playground. This example will demonstrate the following:

  • Declaring a package
  • Importing the fmt package from the standard library, which can print to our screen
  • Declaring the main() function of a program
  • Declaring a string variable using the := operator
  • Printing the variable to the screen

Let's see what this looks like:

1 package main
2 
3 import "fmt"
4
5 func main() {
6    hello := "Hello World!"
7    fmt.Println(hello)
8
9 }

In our first line, we declared the name of our package using the package keyword. The entrance point for any Go binary is a package named main that has a function called main().

In our third line, we import the fmt package. fmt has functions for doing string formatting and writing to various outputs.

On our fifth line, we declare a function called main that takes no arguments and returns no values. main() is special, as when a binary is run, it starts by running the main() function.

Go uses {} to show where a function starts and where a function ends (similar to C).

The sixth line declares a variable named hello using the := operator. This operator indicates that we wish to create a new variable and assign it a value in a single line. This is the most common, but not the only, way to declare a variable.

As Go is typed, so := will assign the type based on the value. In this case, it will be a string, but if the value was an integer (such as 3), it would be the int type, and if a floating-point (such as 2.4), it would be the float64 type. If we wanted to declare a specific type, such as int8 or float32, we would need some modifications (which we will talk about later).

On the seventh line, we call a function that is in the fmt package called Println. Println() will print the contents of the hello variable to stdout followed by a new line character (\n).

You will notice that the way to use a function declared in another package is to use the package name (without quotes) + a period + the name of the function. In this case, fmt.Println().

In this section, you have learned how to declare a package, import a package, what the function of the main package is, and how to write a basic Go program with a variable declaration. In the next section, we will go into some depth on declaring and using variables.

Using Go's variable types

Modern programming languages are built with primitives called types. When you hear that a variable is a string or integer, you are talking about the variable's type.

With today's programming languages, there are two common type systems used:

  • Dynamic types (also called duck typing)
  • Static types

Go is a statically typed language. For many of you who might be coming from languages such as Python, Perl, and PHP, then those languages are dynamically typed.

In a dynamically typed language, you can create a variable and store anything in it. In those languages, the type simply indicates what is stored in the variable. Here is an example in Python:

v = "hello"
v = 8
v = 2.5

In this case, v can store anything, and the type held by v is unknown without using some runtime checks (runtime meaning that it can't be checked at compile time).

In a statically typed language, the type of the variable is set when it is created. That type cannot change. In this type of language, the type is both what is stored in the variable and what can be stored in the variable. Here is a Go example:

v := "hello" // also can do: var v string = "hello"

The v value cannot be set to any other type than a string.

It might seem like Python is superior because it can store anything in its variable. But in practice, this lack of being specific means that Python must wait until a program is running before it can find out there is a problem (what we call a runtime error). It is better to find the problem when the software is compiled than when it is deployed.

Let's take a look at a function to add two numbers together as an example.

Here is the Python version:

def add(a, b):
     return a+b

Here is the Go version:

func add(a int, b int) int {
     return a + b
}

In the Python version, we can see that a and b will be added together. But, what types are a and b? What is the result type? What happens if I pass an integer and a float or an integer and a string?

In some cases, two types cannot be added together in Python, which will cause a runtime exception, and you can never be sure of what the result type will be.

Note

Python has added type hints to the language to help avoid these problems. But, practical experience has taught us with JavaScript/Dart/TypeScript/Closure that while it can help, optional type support means that a lot of problems fall through the cracks.

Our Go version defines the exact types for our arguments and our result. You cannot pass an integer and a float or an integer and a string. You will only ever receive an integer as a return. This allows our compiler to find any errors with variable types when the program is compiled. In Python, this error could show up at any time, from the instant it ran to 6 months later when a certain code path was executed.

Note

A few years ago, there was a study done on the Rosetta Code repository for some of the top languages in use to see how they fared in processing time, memory use, and runtime failures. For runtime failures, Go had the least failures, with Python towards the bottom of the ranking. Static typing would have certainly played into that.

The study can be found here: https://arxiv.org/pdf/1409.0252.pdf.

Go's types

Go has a rich type system that not only specifies that a type might be an integer but also the size of the integer. This allows a Go programmer to reduce the size of a variable both in memory and when encoding for network transport.

The following table shows the most common types used in Go:

Table 1.1 – Common types used in Go and their descriptions

Table 1.1 – Common types used in Go and their descriptions

We will be keeping our discussion mostly to the preceding types; however, the following table is the full list of types that can be used:

Table 1.2 – Full list of types that you can use in Go

Table 1.2 – Full list of types that you can use in Go

Go doesn't just provide these types; you can also create new types based on these basic types. These custom types become their own type and can have methods attached to them.

Declaring a custom type is done with the type keyword and will be discussed during the section on the struct type. For now, we are going to move on to the basics of declaring variables.

Now that we've talked about our variable types, let's have a look at how we can create them.

Declaring variables

As in most languages, declaring a variable allocates storage that will hold some type of data. In Go, that data is typed so that only that type can be stored in the allocated storage. As Go has multiple ways to declare a variable, the next parts will talk about the different ways this can be done.

The long way to declare a variable

The most specific way to declare a variable is using the var keyword. You can use var to declare a variable both at the package level (meaning not inside a function) and within a function. Let's look at some examples of ways to declare variables using var:

var i int64

This declares an i variable that can hold an int64 type. No value is assigned, so the value is assigned the zero value of an integer, which is 0:

var i int = 3

This declares an i variable that can hold an int type. The value 3 is assigned to i.

Note that the int and int64 types are distinct. You cannot use an int type as an int64 type, and vice versa. However, you can do type conversions to allow interchanging these types. This is discussed later:

var (
     i int
     word = "hello"
)

Using (), we group together a set of declarations. i can hold an int type and has the integer zero value, 0. word doesn't declare the type, but it is inferred by the string value on the right side of the equal (=) operator.

The shorter way

In the previous example, we used the var keyword to create a variable and the = operator to assign values. If we do not have an = operator, the compiler assigns the zero value for the type (more on this later).

The important concept is as follows:

  • var created the variable but did not make an assignment.
  • = assigned a value to the variable.

Within a function (not at the package level), we can do a create and assign by using the := operator. This both creates a new variable and assigns a value to it:

i := 1                       // i is the int type 
word := "hello"              // word is the string type 
f := 3.2                     // f is the float64 type 

The important thing to remember when using := is that it means create and assign. If the variable already exists, you cannot use :=, but must use =, which just does an assignment.

Variable scopes and shadowing

A scope is the part of the program in which a variable can be seen. In Go, we have the following variable scopes:

  • Package scoped: Can be seen by the entire package and is declared outside a function
  • Function scoped: Can be seen within {} which defines the function
  • Statement scoped: Can be seen within {} of a statement in a function (for loop, if/else)

In the following program, the word variable is declared at the package level. It can be used by any function defined in the package:

package main
import "fmt"
var word = "hello"
func main() {
	fmt.Println(word)
}

In the following program, the word variable is defined inside the main() function and can only be used inside {} which defines main. Outside, it is undefined:

package main
import "fmt"
func main() {
	var word string = "hello"
	fmt.Println(word)
}

Finally, in this program, i is statement scoped. It can be used on the line starting our for loop and inside {} of the loop, but it doesn't exist outside the loop:

package main
import "fmt"
func main() {
	for i := 0; i < 10; i++ {
		fmt.Println(i)
	}
}

The best way to think of this is that if your variable is declared on a line that has {or within a set of {}, it can only be seen within those {}.

Cannot redeclare a variable in the same scope

The rule for this, You cannot declare two variables with the same name within the same scope.

This means that no two variables within the same scope can have the same name:

func main() {
     var word = "hello"
     var word = "world"
     fmt.Println(word)
}

This program is invalid and will generate a compile error. Once you have declared the word variable, you cannot recreate it within the same scope. You can change the value to a new value, but you cannot create a second variable with the same name.

To assign word a new value, simply remove var from the line. var says create variable where we want to only do an assignment:

func main() {
     var word = "hello"
     word = "world"
     fmt.Println(word)
}

Next, we will look at what happens when you declare two variables with the same name in the same scope, but within separate code blocks.

Variable shadowing

Variable shadowing occurs when a variable that is within your variable scope, but not in your local scope, is redeclared. This causes the local scope to lose access to the outer scoped variable:

package main
import "fmt"
var word = "hello"
func main() {
	var word = "world"
	fmt.Println("inside main(): ", word)
	printOutter()
}
func printOutter() {
	fmt.Println("the package level 'word' var: ", word)
}

As you can see, word is declared at the package level. But inside main, we define a new word variable, which overshadows the package level variable. When we refer to word now, we are using the one defined inside main().

printOutter() is called, but it doesn't have a locally shadowed word variable (one declared between its {}), so it used the one at the package level.

Here's the output of this program:

inside main():  world
the package level 'word' var:  hello

This is one of the more common bugs for Go developers.

Zero values

In some older languages, a variable declaration without an assignment has an unknown value. This is because the program creates a place in memory to store the value but doesn't put anything in it. So, the bits representing the value are set to whatever happened to be in that memory space before you created the variable.

This has led to many unfortunate bugs. So, in Go, declaring a variable without an assignment automatically assigns a value called the zero value. Here is a list of the zero values for Go types:

Table 1.3 – Zero values for Go types

Table 1.3 – Zero values for Go types

Now that we understand what zero values are, let's see how Go prevents unused variables in our code.

Function/statement variable must be used

The rule here is that if you create a variable within a function or statement, it must be used. This is much for the same reason as package imports; declaring a variable that isn't used is almost always a mistake.

This can be relaxed in much the same way as an import, using _, but is far less common. This assigns the value stored in someVar to nothing:

_ = someVar

This assigns the value returned by someFunc() to nothing:

_ = someFunc()

The most common use for this is when a function returns multiple values, but you only need one:

needed, _ := someFunc()

Here, we create and assign to the needed variable, but the second value isn't something we use, so we drop it.

This section has provided the knowledge of Go's basic types, the different ways to declare a variable, the rules around variable scopes and shadows, and Go's zero values.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Develop the skills to build command-line tools to control thousands of nodes
  • Use Go to create Terraform providers and GitHub actions and extend Kubernetes
  • Gain the knowledge to build DevOps workflows that are understandable, scalable, and safe

Description

Go is the go-to language for DevOps libraries and services, and without it, achieving fast and safe automation is a challenge. With the help of Go for DevOps, you'll learn how to deliver services with ease and safety, becoming a better DevOps engineer in the process. Some of the key things this book will teach you are how to write Go software to automate configuration management, update remote machines, author custom automation in GitHub Actions, and interact with Kubernetes. As you advance through the chapters, you'll explore how to automate the cloud using software development kits (SDKs), extend HashiCorp's Terraform and Packer using Go, develop your own DevOps services with gRPC and REST, design system agents, and build robust workflow systems. By the end of this Go for DevOps book, you'll understand how to apply development principles to automate operations and provide operational insights using Go, which will allow you to react quickly to resolve system failures before your customers realize something has gone wrong.

Who is this book for?

This book is for Ops and DevOps engineers who would like to use Go to develop their own DevOps tooling or integrate custom features with DevOps tools such as Kubernetes, GitHub Actions, HashiCorp Packer, and Terraform. Experience with some type of programming language, but not necessarily Go, is necessary to get started with this book.

What you will learn

  • Understand the basic structure of the Go language to begin your DevOps journey
  • Interact with filesystems to read or stream data
  • Communicate with remote services via REST and gRPC
  • Explore writing tools that can be used in the DevOps environment
  • Develop command-line operational software in Go
  • Work with popular frameworks to deploy production software
  • Create GitHub actions that streamline your CI/CD process
  • Write a ChatOps application with Slack to simplify production visibility

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 08, 2022
Length: 634 pages
Edition : 1st
Language : English
ISBN-13 : 9781801818896
Vendor :
Google
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jul 08, 2022
Length: 634 pages
Edition : 1st
Language : English
ISBN-13 : 9781801818896
Vendor :
Google
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 177.97
The Kubernetes Bible
$64.99
Event-Driven Architecture in Golang
$49.99
Go for DevOps
$62.99
Total $ 177.97 Stars icon

Table of Contents

21 Chapters
Section 1: Getting Up and Running with Go Chevron down icon Chevron up icon
Chapter 1: Go Language Basics Chevron down icon Chevron up icon
Chapter 2: Go Language Essentials Chevron down icon Chevron up icon
Chapter 3: Setting Up Your Environment Chevron down icon Chevron up icon
Chapter 4: Filesystem Interactions Chevron down icon Chevron up icon
Chapter 5: Using Common Data Formats Chevron down icon Chevron up icon
Chapter 6: Interacting with Remote Data Sources Chevron down icon Chevron up icon
Chapter 7: Writing Command-Line Tooling Chevron down icon Chevron up icon
Chapter 8: Automating Command-Line Tasks Chevron down icon Chevron up icon
Section 2: Instrumenting, Observing, and Responding Chevron down icon Chevron up icon
Chapter 9: Observability with OpenTelemetry Chevron down icon Chevron up icon
Chapter 10: Automating Workflows with GitHub Actions Chevron down icon Chevron up icon
Chapter 11: Using ChatOps to Increase Efficiency Chevron down icon Chevron up icon
Section 3: Cloud ready Go Chevron down icon Chevron up icon
Chapter 12: Creating Immutable Infrastructure Using Packer Chevron down icon Chevron up icon
Chapter 13: Infrastructure as Code with Terraform Chevron down icon Chevron up icon
Chapter 14: Deploying and Building Applications in Kubernetes Chevron down icon Chevron up icon
Chapter 15: Programming the Cloud Chevron down icon Chevron up icon
Chapter 16: Designing for Chaos Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(16 Ratings)
5 star 75%
4 star 12.5%
3 star 6.3%
2 star 0%
1 star 6.3%
Filter icon Filter
Top Reviews

Filter reviews by




Thomas Niu Feb 06, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Feefo Verified review Feefo
Amazon Customer Aug 08, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is very well written and the selection of topics is spot one. Bravo!
Amazon Verified review Amazon
Tiny Oct 14, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If you need to upgrade your current Go proficiency to work in the new development environment, “Go for Devops” Packt, by John Doak and David Justice can help. The book does an excellent job reintroducing the reader to go basics, building out observability solutions, and then migrating those solutions onto the cloud. Each section provides an extensive code-base and real-world examples to help learn the best solutions. My own Go skills have been lacking and I found the first section extremely helpful. It covers from language basics to command line tooling with all the intermediate sections to build file-structures and connect to remote resources. These skills play in later when needed to construct environments on cloud-providers and detail the observability aspects required by DevOps. If you don’t have the basic skills, you can’t move to advanced options and this does a credible job covering down on those basics. My favorite part of the middle section was the connection with existing tools. I don’t know any developers that haven’t used GitHub as a core piece so learning to automate workflows with GitHub builds a much needed skill-set. I also use Open Telemetry extensively myself to help send the right data to the right places so seeing it covered here was useful. Even further, the authors point out the ability to integrate OWASP’s Zap, and then the Jaeger tool with OTel to show results effectively. The last part builds to infrastructure as code with Terraform and then expand into Azure. This is a good spot for a joke, Do you know why there is no DevOps on Mars? It hasn’t been terraformed. With that, terraform is a key piece of most DevOps infrastructure so the inclusion here is valuable. Past terraform, the authors build some container solutions with Kubernetes and explain how to construct an Azure environment. Each of these steps helps the advanced user build and monitor a DevOps environment to continuous generate code for production. My chief complaint was I was really looking forward to the chapter on Chaos. I thought it would be some interesting takes on doing Chaos engineering against Go code for my CI/CD pipelines. The chapter did offer some best practices, but more in line with standard approaches than a detailed Chaos look. All in all, not too bad of a downer for an otherwise great book. This book provides a great, intermediate look at using Go in your DevOps process. While it does not exclusively focus on DevOps approaches, the integration with the various code aspects will certainly improve your overall code development. I recommend this for anyone working development in Go with an interest in expanding their knowledge to infrastructure as code.
Amazon Verified review Amazon
R. D. Mann Jul 16, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Sure, I am (the first person) listed in the acknowledgement from one of the authors - John Doak - but I wouldn't provide a review if I didn't believe in the fundamentals of what he and David Justice provide in this tome. While there will be many perspectives of what being a DevOps role entails - and which languages you could leverage - the fact is GO is largely defacto 'go to' and John has been a promoter/evangelizer for well over 10 years at this point. Many of the anecdotal stories are true, some watered down but the premise and deliverable in each chapter builds out a tool chest that any size org can take advantage of - now GO and get yourself a copy of this book and put yourself into gear.
Amazon Verified review Amazon
R. Rose Jul 24, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I bought this book based on an initial read of the overview. Despite being quite a long book, I managed to read it over a couple of days.To summarise this is an excellent overview of how to build tooling with the Go Language. It covers a wide range of problem areas which should be familiar to anyone working in DevOps.Of specific merit is the chapter on moving from bash to Go as a scripting runner. Loved the detail of how to check the command environment to ensure it contains the necessary components. Also covers handling different data formats (e.g. csv, json and yaml) - which is actually super useful if you need to work between various systems.Later in the book - there is some coverage of how to use tools like Hashicorp Packer (generate a custom image) and Terraform (build a provider). The book also covers examples on Cloud Providers; AWS and Azure - it didn't take too much effort to use Google Cloud to be fair.If you have an interest in Go and need to build tooling to help in a variety of scenarios, this book is a great start on that journey.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.