1. Home
  2. Training Library
  3. DevOps
  4. Courses
  5. Introduction to the Go Programming Language

Introducing Go

play-arrow
Introducing Go
Overview
DifficultyBeginner
Duration2h 17m
Students134
Ratings
5/5
star star star star star

Description

If you're thinking about engineering the next big dotcom application then you should seriously consider using Go!! 

The Go Programming Language is without doubt one of the hottest languages to learn, particularly in this cloud native era. More and more companies are adopting Go to engineer highly performant, stable and maintainable applications. Popular projects such as Docker, Kubernetes, Terraform, Etcd, Istio, InfluxDB have all been built successfully using Go!! 

This introductory level training course is designed to bring you quickly up to speed with the many key features that the Go programming language provides. You'll also learn how to setup your own Go development environment - consisting of the Go toolchain, Visual Studio Code, and several related Go based extensions - all to ensure that you are able to be productive writing your own source code.

We’d love to get your feedback on this course, so please give it a rating when you’re finished. If you have any queries or suggestions, please contact us at support@cloudacademy.com.

Learning Objectives

By completing this course, you will:

  • Learn about what makes Go a great language
  • Learn how to install the Go toolchain
  • Learn how to setup Visual Studio Code to edit and debug Go programs
  • Learn how to work with the Go Playground to test and run snippets of Go code
  • Learn and understand the basic Go language syntax and features
  • Learn how to use the Go tool chain commands to compile, test, and manage Go code
  • And finally, you’ll learn how to work with and manage Go modules for module dependency management

Intended Audience

This course is intended for:

  • Anyone interested in learning the Go Programming Language
  • Software Developers interested in using Go to compile and test Go based applications
  • DevOps practitioners looking to learn about Go to support Go based applications

Prerequisites

To get the most from this course, you should have at least:

  • A basic understanding of software development and the software development life cycle

Source Code

All sample Go source code as used and demonstrated within this course can be found here:

Transcript

- [Jeremy Cook] Welcome back. In this lecture I'm going to introduce you to the Go programming language, where it came from and what motivated its design. Go was first released in open source to the community in 2009 by Google and has grown in popularity year on year. Go excels at systems programming and concurrency requirements. When you consider the success of projects like Docker, Kubernetes, Terraform, Etcd, Istio, InfluxDB, the list goes on, all of these projects were built using Go. The success and wide adoption of each of these projects is testament to Go's ability as a language that is productive, performant, and stable. The original motives for designing Go were primarily to build a lightweight language that had strong support for concurrency which, once compiled, could make better use of multi-core systems. This was to address Google's continued thirst for processing large amounts of data as quickly as possible and as often as possible. While setting out to achieve this they also decided that they wanted the new language to combine the best traits of other popular languages and, therefore, designed it to have the performance and safety of compiled languages such as C and C++. 

As of early 2020, the latest release of Go sits at version 1.13. This particular version makes Go once again more performant, more robust, and more mature than previous versions with the latest version focusing on bringing stronger support, tooling, and workflow management for managing and maintaining module dependencies. In the coming slides I'll drill into many of the benefits that should motivate you into learning Go. The Go language syntax is simple and very minimalistic by design. This has the effect of making it perhaps less expressive when compared with other languages such as Ruby and Python but it does make the code easier to read, maintain, and learn. 

The language looks and feels a bit like C. It is typed and comes with a primitive set of data types, all of which you would expect. The language is opinionated which helps you to write code in a best practice manner. Go isn't strictly object orientated. For example, the language lacks the concept of inheritance. Regardless, it still has object orientated-like features such as custom struck types, methods, and dot notation for accessing. The language is designed in such a way as to preference composition over inheritance which many believe to be a better way of structuring applications. As early I mentioned, the Go language is statically typed meaning the Go compiler checks for and catches type mismanagement errors at compile time. The compiler checks for incorrect type conversions and casts that would fail, as well as many other issues. 

The compiler is also designed to discover and error out on any unused variables that may have been declared but are never actually used. This may not sound like a big deal but when your applications are being built to run mission critical workloads at scale and to be hardly performant then having the knowledge that your code compiles safely and is optimized will give you a level of comfort not afforded to other dynamic and interpreted languages. 

The Go Toolchain provides a number of useful static analysis tools which, when used, helps to ensure that your Go application remains maintainable and performs as desired at runtime. Example static analysis tools are gofmt used to reformat source code layout according to Go's opinionated best practices, golint used to report on and enforce semantical and syntactical practices and go vet used to report on suspicious or abnormal or just nonsensical code in your application. As good practice these static analysis tools can and should be integrated into your Go CICD pipelines so that they are rerun over the code each and every time a build is performed. 

Go ships with and installs a full featured Standard Library which provides all of your basic and midrange requirements for data processing, network connectivity, security, cryptography, IO, and the list goes on. The Standard Library provides many useful built-in functions that help you to manipulate the primitive data types. The Standard Library even provides web server-like support that makes it trivial to stand up an HTTP web service within your Go applications. Working with data formats, such as JSON and or XML again is trivial with the serialization and deserialization support already packaged within the Standard Library for these formats. 

The latest 1.13 release of Go now provides support for modules, the official tool and workflow for dependency management. Go module functionality has been integrated directly into the Go Toolchain making the developer's workflow involving third party open source projects much simpler and more robust than in the past. The Go Toolchain will automatically check and detect import statements when a build is performed, and if required, download the module making it available locally so that compilation succeeds. Semantic Versioning is used to tag modules ensuring that your code uses the correct version when multiple versions of the dependent module exist. When it comes to assessing performance Go is right up there with the most performant languages such as C. 

Go's language from the outset was designed to exploit multi-core machines and therefore brings a lot to the table when building the applications. Building applications that run concurrently across multiple cores and multiple machines is a sweet spot for Go. Go's compiler is also renowned for being speedy with build times completing in seconds rather than minutes often being the case. Again, this was by intent and, in fact, was one of the very early motives for creating Go. Go's simple language design allows the compilation phases to be quick which benefits developers two-fold, less of the language to learn and understand, and faster and rapid build times. Go's compiler produces a single binary with all runtime dependencies compiled and packaged within it. The beauty of this is that it removes the need for you to manage and install external requirements to make it run and unlike Java it doesn't need a runtime engine installed. From the perspective of DevOps dealing with and maintaining a single binary is a walk in the park compared to alternatives. Go also has the cool ability to compile the same source code without modification for various operating systems and process architectures including Linux, Windows, and MacOS. The Go language really differentiates itself from competitor languages when it comes to implementing concurrency. 

The Go language introduces the concepts of go routines and channels which, when combined, makes it incredibly straightforward and almost trivial to build applications that have multiple forks of asynchronous work being performed. Go applications target multi-core systems and its ability to do so helps application scale. At runtime, Go uses garbage collection so that you don't have to implement memory management yourself. This keeps your code clean and safe and keeps you focused on building business value rather than being distracted with memory management issues. The garbage collector is fast and keeps getting faster and more optimized with each new release of Go. 

The Go Standard Library ships with a testing package which provides really excellent support for building and writing unit tests. Go encourages writing unit test files in the same location as the code it is testing using the file naming convention of name of the file under test underscore test dot go. The Go test runner will then find these files and execute them as unit tests. Nice and easy. The final area of interest I'll call out when working with Go is the Go Playground. Although, not strictly part of the Go language, nor the runtime, the Go Playground provides an extremely useful service to those who are just starting out on their Go adventure. The Go Playground is a web based application located at https://play.golang.org. You can use it to test out and prototype various code snippets without having to install or set up the Go Toolchain locally. Later on in the course I will use it to demonstrate many of the Go language syntax features. 

Okay that completes the lecture on the many benefits associated with the Go programming language. Go ahead and close this lecture and I'll see you shortly in the next one.

About the Author

Students18669
Labs32
Courses78
Learning paths17

Jeremy is the DevOps Content Lead at Cloud Academy where he specializes in developing technical training documentation for DevOps.

He has a strong background in software engineering, and has been coding with various languages, frameworks, and systems for the past 20+ years. In recent times, Jeremy has been focused on DevOps, Cloud, Security, and Machine Learning.

Jeremy holds professional certifications for both the AWS and GCP cloud platforms.
 

Covered Topics