Book Image

Network Automation with Go

By : Nicolas Leiva, Michael Kashin
Book Image

Network Automation with Go

By: Nicolas Leiva, Michael Kashin

Overview of this book

Go’s built-in first-class concurrency mechanisms make it an ideal choice for long-lived low-bandwidth I/O operations, which are typical requirements of network automation and network operations applications. This book provides a quick overview of Go and hands-on examples within it to help you become proficient with Go for network automation. It’s a practical guide that will teach you how to automate common network operations and build systems using Go. The first part takes you through a general overview, use cases, strengths, and inherent weaknesses of Go to prepare you for a deeper dive into network automation, which is heavily reliant on understanding this programming language. You’ll explore the common network automation areas and challenges, what language features you can use in each of those areas, and the common software tools and packages. To help deepen your understanding, you’ll also work through real-world network automation problems and apply hands-on solutions to them. By the end of this book, you’ll be well-versed with Go and have a solid grasp on network automation.
Table of Contents (18 chapters)
1
Part 1: The Go Programming Language
6
Part 2: Common Tools and Frameworks
10
Part 3: Interacting with APIs

Why Go?

When choosing which programming language to learn next, most people focus mainly on technical reasons. We believe that the choice can be a bit more nuanced, so we try to approach this question from different angles. We start with non-technical arguments, something that's often overlooked but that we believe is important and can have a major impact on both the learning process and day-to-day use. Following that, we cover generic technical arguments that help Go stand out in the very competitive landscape of modern programming languages. We close out this section by exploring different facets of Go that can benefit people, specifically in the fields of networking and network automation.

Non-technical reasons

Whether you are new to the language or have some experience with it, you can access more experienced Go developers in the community who are willing to help you learn more about the language. We include some pointers to community resources and go through the adoption and popularity of Go.

Last but not least, we want to address the maturity of the language, whether it's still in development, and where Go is headed in the future.

Community

A healthy community is almost always an attribute of a successful project. The Go programming language is no exception, with its welcoming and growing community of Go developers—Gophers, with about 2 million of them in the world, according to Russ Cox's article, How Many Go Developers Are There? (Further reading). You can see Renée French's Go Gopher mascot here:

Figure 1.1 – Go Gopher, by Renée French

Figure 1.1 – Go Gopher, by Renée French

The Go user community has several places where newcomers can ask questions and get help from more experienced Go developers, as listed here:

  • golang-nuts mailing list (Further reading)—Google Groups mailing list for any generic language discussions
  • Go Forum (Further reading)—a standalone forum for technical discussions, release announcements, and community updates
  • Go Language Collective (Further reading)—the official question-and-answer (Q&A) channel on Stack Overflow
  • Gophers Slack channel (Further reading)—a place for generic and topic-specific discussions, including a dedicated networking channel

If you want more live interactions, there are some options available as well, as outlined here:

  • A good deal of in-person meetups are available via the Go Developers Network (GDN) (Further reading).
  • One of the principal events in the Go community is GopherCon, held regularly in different parts of the world.
  • The official Go wiki page hosted on GitHub keeps track of all future and past Go conferences and major events (Further reading).

Popularity

Ever since its foundation in the late 2000s, Go has gained a lot of interest from the developer community, not least because of who was behind it. Developed by a group of some of the best computer scientists employed by Google to solve the problems of C/C++, Go is a language that's both simple to understand and nearly as efficient as its predecessors. It took a few years to mature, but it had soon become the new hot start up language, and many up-and-coming software companies such as Docker and HashiCorp adopted it.

Most recently, the Stack Overflow Developer Survey 2021 (Further reading) recognized Go as one of the top three most wanted programming languages by developers. Continuous support from its mothership, and the success of Kubernetes, have made it a de facto standard language to write cloud-native applications with such notable projects as Istio, CoreDNS, Prometheus, and Grafana. As more and more users adopt these applications, it's hard to imagine Go's popularity waning in the future.

Here are a few extra data points in support of Go's rising popularity that are worth mentioning:

  • 225 out of 291 Cloud Native Computing Foundation (CNCF) projects use Go, as reported in the CNCF DevStats toolset (Further reading).
  • Go ranks third as the language with the most stars on GitHub, according to GitHut 2.0 (Further reading).
  • Go is behind three out of the four most popular development tools (Docker, Kubernetes, and Terraform) (Further reading).
  • Go is in the top 10 of the Stack Overflow Developer Survey 2021's top-paying technologies ranking (Further reading).

Maturity

While the Go team released Go (version 1) not too long ago (March 2012), Go has been getting minor changes ever since. The language designers assume a strict position against adding unnecessary features that may result in feature creep. At GopherCon 2014's opening keynote, Rob Pike made this comment explicitly: "The language is done." Russ Cox also mentioned this in his article Go, Open Source, Community (Further reading), referring to Go 1 specifically.

This doesn't mean Go does not have its fair share of pain points. For example, dependency management has been a problem the Go team addressed fairly recently with the introduction of Go modules to better group Go packages you release together. There was also a lack of generics support, a feature that the Go team is now introducing in Go 1.18, probably the most significant change since the release of Go (version 1). Now, users can represent functions and data structures with generic types, which enables code reuse. This addresses one of the primary requests from the community, as Go Developer Survey 2020 Results shows (Further reading).

Despite that, these few changes are very selective and designed to dramatically improve developer productivity. It's safe to assume that we won't see a situation where you have to learn new language concepts and idioms every year and have to rewrite your code to maintain forward compatibility. The Go 1 compatibility guarantee in Go 1 and the Future of Go Programs (Further reading) states the following:

It is intended that programs written to the Go 1 specification will continue to compile and run correctly, unchanged, over the lifetime of that specification. ...code that runs under Go 1.2 should be compatible with Go 1.2.1, Go 1.3, Go 1.4, and so on.

Go benefits from the lessons learned from other programming languages. Pascal, Oberon, C, and Newsqueak are among the languages that influenced Go. We explore their impact in Chapter 2, Go Basics.

Go follows a 6-month release cycle (Further reading). In the Go release notes for each version (Further reading), there is a section at the top that describes changes to the language, which in general is very brief or empty. Over the last couple of years, they reported only four small enhancements to the language, which is a good sign of maturity.

How much Go will change in the future is something we discuss in the next section.