
Go Programming Language For Dummies
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
Now is the perfect time to learn the Go Programming Language. It's one of the most in-demand languages among tech recruiters and developers love its simplicity and power. Go Programming Language For Dummies is an easy way to add this top job skill to your toolkit. Written for novice and experienced coders alike, this book traverses basic syntax, writing functions, organizing data, building packages, and interfacing with APIs.
Go--or GoLang, as it's also known--has proven to be a strong choice for developers creating applications for the cloud-based world we live in. This book will put you on the path to using the language that's created some of today's leading web applications, so you can steer your career where you want to Go!
* Learn how Go works and start writing programs and modules
* Install and implement the most powerful third-party Go packages
* Use Go in conjunction with web services and MySQL databases
* Keep your codebase organized and use Go to structure data
With this book, you can join the growing numbers of developers using Go to create 21st century solutions. Step inside to take start writing code that puts data in users' hands.
More details
Other editions
Additional editions

Person
Content
Chapter 1
Hello, Go!
IN THIS CHAPTER
Understanding why Go is the wave of the future
Installing Go on your computer
Working with an integrated development environment
Writing a Go program and understanding how it works
Seeing how Go compares to other languages
Go is an open-source programming language - one of the fastest-growing programming languages around - released by Google in 2009. It's a multipurpose programming language specifically designed to build fast, scalable applications.
Go comes from a pretty impressive team of people: Ken Thompson (designer and creator of Unix and C), Rob Pike (cocreator of UTF-8 and Unix format), and Robert Griesemer (a Google engineer). If you're technically inclined, you may want to check out an article called "Go at Google: Language Design in the Service of Software Engineering" (https://talks.golang.org/2012/splash.article), which discusses how Go was initially conceived to solve problems at Google.
In this chapter, I explain why learning Go is important for your career, where Go can be used, and how to get started with Go programming.
Go is often referred to as Golang because of its web address: https://golang.org. However, the official name of the language is Go, so that's how I refer to it throughout this book.
Seeing What Learning Go Can Do for You
You can learn many programming languages today, but Go stands out from the others for a few reasons:
-
Go is easy to learn. Go's syntax makes it a readable language. It has no support for object-oriented programming (OOP), which means you don't have to worry about classes and inheritance and the complexities that come with that.
Object-oriented programming (OOP) is a programming paradigm that is based on the concept of objects (data). Instead of focusing on the functions and logics, OOP organizes software around data, or objects. A key concept in OOP is classes (sort of like templates). Suppose you want to display buttons in your application. Instead of writing the code to display each button individually, you can create a class to represent a generic button and use it to create buttons to display in your application. Each button has its own properties (characteristics). Using the concept of inheritance in OOP, you can create multiple subclasses of the button class to create different types of buttons, such as a rounded button, a rectangular button, and so on.
- Go has fewer features than other programming languages. You don't have to worry about the best way to solve a problem - there is only one right way to solve a problem in Go. This makes your codebase easy to maintain.
- Go excels in concurrent programming. Go's support for Goroutines makes it extremely easy to run multiple functions concurrently.
Go has no support for generics (the ability to specify the actual data type until it's actually used), but this may change as the language evolves.
If you still aren't convinced that you should learn Go, perhaps this next bit of news will motivate you: In the Stack Overflow Developer Survey 2019 (https://insights.stackoverflow.com/survey/2019), Go developers were the third highest paid in the industry, behind Clojure and F# developers.
Although Go has been around for quite a while (since 2009), only recently did it get wide adoption by developers, thanks to the proliferation of cloud computing and microservices. Today, Go has been widely used by major companies such as Dailymotion, Dropbox, Google, and Uber.
Here are some examples of where Go can be used:
- Cloud services: You can build scalable apps using Go on the Google Cloud Platform (GCP).
- Networking apps: With Go's support for Goroutines, you can use Go to build distributed servers and application programming interfaces (APIs).
- Web services: You can use Go to build scalable and efficient web services.
- Command-line apps: Because Go runs on multiple platforms, you can compile the same codebase and target different platforms (such as those running on macOS and Windows).
Installing Go on Your Machine
You're probably very eager to get started with Go programming on your machine, so let's get to it!
The easiest way to install Go is to go to https://golang.org/doc/install. This website automatically detects the operating system (OS) you're using and shows you the button to click to download the Go installer (see Figure 1-1).
FIGURE 1-1: Downloading the Go installer.
This book code has been written and tested using Go version 1.15. When you're reading this book, a new version of Go may have been released. In order to ensure that you can follow the examples in this book, I strongly suggest that you install the same version of Go that I've used. You can find it here:
- macOS:
https://golang.org/dl/go1.15.8.darwin-amd64.pkg - Windows:
https://golang.org/dl/go1.15.8.windows-amd64.msi
If you want to be able to choose the Go installer for each of the supported operating systems (Linux, macOS, and Windows), and even see the source code for Go, go to https://golang.org/dl/.
After you've downloaded the Go installer, double-click the installer to start the straightforward installation process. I recommend that you just use the default installation settings - you don't need to change any of those settings.
In the following sections, I show you how to verify that your installation is performed successfully on macOS and Windows.
macOS
On macOS, the Go installer installs the Go distribution in the /usr/local/go directory. It also adds the /usr/local/go/bin directory to your PATH environment variable. You can verify this by entering the following command in the Terminal app (which you can find in the Applications/Utilities folder):
$ echo $PATH
You should see something like the following output (note the added path, highlighted in bold):
/Users/weimenglee/opt/anaconda3/bin:/Volumes/SSD/opt/anaco
nda3/condabin:/Users/weimenglee/flutter/bin:/Users/weimeng
lee/go/bin:/Users/weimenglee/.nvm/versions/node/v9.2.0/bin
:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/g
o/bin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/App
le/usr/bin:/Library/Frameworks/Mono.framework/Versions/Cur
rent/Commands
Make sure to restart the Terminal app after you've installed Go in order for the changes to take effect.
To verify that the installation is correct, type the following command in Terminal:
$ go version
You should see the version of Go installed on your system:
go version go1.15.8 darwin/amd64
Windows
On Windows, the Go installer installs the Go distribution in the C:\Go directory. It also adds the C:\Go\bin directory to your PATH environment variable. You can verify this by entering the following command in Command Prompt (which you can find by typing cmd in the Windows search box):
C:\Users\Wei-Meng Lee>path
You should see something like the following output (note the added path, highlighted in bold):
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\
Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WIND
OWS\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program
Files\Microsoft SQL Server\130\Tools\Binn\;C:\Go\bin;
C:\Program Files\Git\cmd;C:\Program Files\Graphviz
2.44.1\bin;C:\Program Files\CMake\bin;C:\Program
Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDes
ktop\version-bin;C:\Program Files\MySQL\MySQL Shell
8.0\bin\;C:\Users\Wei-Meng Lee\AppData\Local\
Microsoft\WindowsApps;;C:\Users\Wei-Meng Lee\
AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Wei-
Meng Lee\.dotnet\tools;C:\Users\Wei-Meng Lee\go\bin
Make sure to restart the Command Prompt window after you've installed Go in order for the changes to take effect.
To verify that the installation is correct, type the following command in Command Prompt:
C:\Users\Wei-Meng Lee>go version
You should now see the version of Go installed on your computer:
go version go1.15.8 windows/amd64
Using an Integrated Development Environment with Go
To develop applications using Go, you just need a text editor (such as Visual Studio Code, TextEdit on macOS, or even the old trusty NotePad), and you're good to go (pun unintended). However, many developers prefer to use...
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.