image
Imports
Start course
Difficulty
Beginner
Duration
2h 17m
Students
3933
Ratings
4.6/5
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] Writing Go code typically requires functionality declared from within other packages. To enable the use of exported types and/or functions declared and contained within other packages, whether they are provided as part of the standard Go library, or by 3rd party providers, you use the import statement to import them into the current package. The import keyword is followed by the import path of the package provided in double quotes. 

A package's import path is its module path joined with its subdirectory within the module itself. All of the standard library packages can be imported using just their package name only. There is no need to declare the module path, since the compiler already knows where to find them based on the local Go tool chain installation and configuration. 

The import keyword can be used to import one or multiple packages at a time. When multiple packages are imported, the import keyword only needs to be specified once, with the packages being listed out within parenthesis. This style helps by making the code more readable. Lines 3 through to 7 demonstrate this approach. External packages that have been made public, and of which are quite often stored on GitHub, can be imported using their GitHub repo URL. The Go tooling is clever enough to connect to GitHub and then download the package locally. This can be seen in the example here on line 6, where I'm utilizing Google's UUID package. 

Imported packages can also be aliased to avoid package naming conflicts. In the case that there are two packages, which share the same name but for which come from different locations and implement different things, an alias can be assigned to one or both to ensure that when their functionality is called upon, the right code gets compiled and executed. For example, I have aliased the math package on line 10 with the m alias. 

Now, if you look closely at all of the functions that are invoked on any of the imported packages, you will see that they all begin with a capital letter. The functions I'm referring to are ToUpper, New, ParseFloat, and Round, and as just stated they all start with a capital letter. It is this convention that actually makes them exported, meaning that they can be seen from outside of the package that they were declared within and can be imported into and invoked from within other packages. This will be covered in more detail as we progress. Running this example provides the following output. 

In summary, you've observed how to use the import keyword to import packages, how to group multiple import statements together, how to use aliases in import statements, how aliases can be used to alias imported packages, and how to import external public packages hosted on GitHub.

About the Author
Students
143802
Labs
71
Courses
109
Learning Paths
209

Jeremy is a Content Lead Architect and DevOps SME here at Cloud Academy where he specializes in developing DevOps technical training documentation.

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

Jeremy holds professional certifications for AWS, Azure, GCP, Terraform, Kubernetes (CKA, CKAD, CKS).

Covered Topics