Schweitzer Fachinformationen
Wenn es um professionelles Wissen geht, ist Schweitzer Fachinformationen wegweisend. Kunden aus Recht und Beratung sowie Unternehmen, öffentliche Verwaltungen und Bibliotheken erhalten komplette Lösungen zum Beschaffen, Verwalten und Nutzen von digitalen und gedruckten Medien.
Tackle GoLang with practical and employment-focused instruction
In Job Ready Go, software education guru Dr. Haythem Balti delivers an essential and hands-on guide to Go, an open-source programming language developed by Google engineers to combine the most sought-after capabilities of other programming languages, including Java, C#, and C++. In the book, the author walks you through all the most critical skills necessary for successful, on-the-job Go programming.
You'll discover:
Job Ready Go offers readers straightforward and elegant instruction based on the renowned mthree Global Academy and Software Guild training program. It's an essential read for aspiring Go developers looking for a fast-track to developing real-world skills demanded by employers.
HAYTHEM BALTI, PhD, is an associate dean at Wiley Edge. He has created courses used by thousands of Software Guild and Wiley Edge (formerly mthree) alumni to learn Go, Java, Python, and other development and data science skills.
KIMBERLY A. WEISS is a Senior Manager of Curriculum Operations for Wiley Edge. She has worked with multiple universities as well as corporate training settings to develop interactive instructional content appropriate for the target learners and course goals, specializing in software development courses.
About the Authors v
About the Technical Writer vi
About the Technical Editor vii
Acknowledgments viii
Introduction xxi
Part I: The Basics of the Go Programming Language 1
Lesson 1: Getting Started with Go 3
Lesson 2: Understanding Go Basics 21
Lesson 3: Storing with Variables 39
Lesson 4: Performing Operations 69
Lesson 5: Controlling Program Flow with Conditional Statements 99
Lesson 6: Controlling Program Flow with Loops 123
Lesson 7: Pulling It All Together: Income Tax Calculator 145
Part II: Organizing Code and Data in Go 173
Lesson 8: Using Functions 175
Lesson 9: Accessing Arrays 195
Lesson 10: Working with Pointers 215
Lesson 11: Organizing with Structs 237
Lesson 12: Accessing Slices 263
Lesson 13: Manipulating Maps 287
Lesson 14: Creating Methods 305
Lesson 15: Adding Interfaces 325
Lesson 16: Pulling It All Together: Building a Burger Shop 343
Part III: Creating Job Ready Solutions in Go 377
Lesson 17: Handling Errors 379
Lesson 18: Concurrency 395
Lesson 19: Sorting and Data Processing 421
Lesson 20: File I/O and OS Operations 453
Lesson 21: Pulling It All Together: Word Analysis in Go 485
Part IV: Advanced Topics for Go Development 525
Lesson 22: Testing 527
Lesson 23: API Development Tutorial 561
Lesson 24: Working with gRPC 591
Lesson 25: Pulling It All Together: Using Smart Data 607
Lesson 26: Using Modules 645
Appendix: File Permissions and Access Rights 651
Index 655
Go is an open source programming language developed and distributed by Google. In this lesson, we will walk through the steps of installing Go on a computer running Microsoft Windows 10 or later.
By the end of this lesson, you will be able to:
NOTE There are also versions of Go for Apple macOS and Linux that you can download. The process should be somewhat similar to what is shown in this lesson.
There are several requirements for installing Go. First, you must have administrative rights on your computer. If you own the computer, you should have no problems. If you are using a work or school computer, contact your IT department if you run into permission problems during the installation process.
NOTE If you have used Go in the past and already have it installed on your computer, you can skip the installation instructions and go straight to the testing steps.
Alternatively, if you have an older version of Go that you would like to update, you might want to remove the existing version before installing the updated version.
You will also need a text or code editor to create Go programs. Go programs are written in plain text, so if you already have an editor you like, you can continue using it. If you have never used a code editor before or if you want to try a different one, you can use one of the following:
https://code.visualstudio.com
https://atom.io
You can also find additional editors that support Go by going to the "Editor plugins and IDEs" page on the Go site. The page is found at https://go.dev/doc/editors.html. You can also use a plain-text editor such as Notepad if you prefer; however, an editor that supports Go, such as Visual Studio Code or Atom, will provide tools to help you with errors in your code.
https://go.dev/doc/editors.html
The first step is to download the most current version of the installation files. You can find the files on Go's Downloads page at https://go.dev/dl. The instructions shown in Figure 1.1 are for version 1.17.2 for Windows, but you will likely see a more recent version on the page.
https://go.dev/dl
Click the link for your operating system in the Featured Downloads section of the page. This will download the necessary installation file or package for your operating system.
Figure 1.1: The Go Downloads page
Once you have downloaded the installation file, open it from your computer. In Windows, you can open it by simply clicking the filename. This will start the Setup Wizard, as shown in Figure 1.2.
Click Next to begin the installation. The next screen displays the End-User License Agreement, as shown in Figure 1.3.
Go is distributed under an open source license. This means that you can modify and/or redistribute the code if you wish, but you must include the same copyright notice in any package you distribute.
You should read through the licensing agreement and then select the check box to accept it. Click Next to continue the installation. The next screen, shown in Figure 1.4, asks you to specify the destination folder where Go will be installed.
Figure 1.2: The Go Setup Wizard
Figure 1.3: The Go End-User License Agreement
Figure 1.4: Specifying the folder where Go will be installed
You can either accept the default location or set a new location by entering the path to a folder or by clicking on Change to select a new location to install Go. Once you've entered the destination folder, click Next again. On the next screen, click the Install button to start the installation. Note that you might be prompted by Windows asking if you give permission to install the application. If so, you will need to indicate that it is okay.
When the installation is complete, you will see a confirmation message when the installation is complete, similar to what is shown in Figure 1.5. You can click the Finish button to close the wizard.
Figure 1.5: Confirmation that Go is installed
NOTE If you are using the MSI installer shown here, it will also set up your computer with the required environment variables during the installation.
After completing the installation, you should test to make sure Go works. To do this in Windows, start by opening a command-line window. Click the Start Menu and type cmd in the search box. You can then open the command prompt from the search results, as shown in Figure 1.6.
NOTE Alternatively, you can open the command prompt by pressing Windows key+R, entering cmd, and clicking the OK button.
Figure 1.6: Running the command prompt (Microsoft Windows 11)
The command prompt will open in a new window similar to Figure 1.7. You should see a prompt that ends in your username.
Figure 1.7: The command prompt
At the prompt, type the following command and press Enter:
go version
This command checks that Go is installed on your computer and displays the version number if it is. You should see a version that matches the one you just installed. Figure 1.8 shows version go1.17.2 installed.
If you get an error message instead of a version number, repeat the installation instructions and try again.
The default installation shown here used the MSI file. If entering the code snippet displayed the version number, then you should be ready to continue creating your first program, Hello World!.
If you downloaded a zip file instead of an MSI file, you will need to manually set up Windows environment variables before using Go. You can either delete the files created from the zip file and reinstall using the MSI file (which sets up the variables during the installation) or use the instructions provided in Go's Download and install page at https://go.dev/doc/install.
https://go.dev/doc/install
Figure 1.8: Displaying your Go version
With Go installed on your machine, you are ready to write and run your first Go program, Hello, World!. Using your preferred text or code editor (such as Atom or Visual Studio Code), create a file named gotest.go and save it to a known location, such as your Documents folder. In the example presented in Listing 1.1, the file is saved in Documents\GoLang. If you choose a different location, you will need to modify the instructions for compiling and running the program.
gotest.go
Documents
Documents\GoLang
Make sure that the file has the filename extension .go. Most text or code editors will allow you to specify your own extension. Verify that the Save As box is set to All Files (or something similar) rather than a specific extension, such as .txt.
.go
.txt
Add the code shown in Listing 1.1 to your new file.
Hello, world!
package main
import "fmt"
func main() {
fmt.Println("Hello, world!")
}
At this time, you are not expected to understand all the code presented in Listing 1.1; however, it is worth taking a closer look. You start by creating a main package to serve as the starting point for your program. You follow this by using the import statement to import Go's formatting package fmt. The fmt package contains code that allows text to be printed to the screen.
main
import
fmt
NOTE The nice thing about using a package like fmt is that you can use it without having to worry about the code. In Listing 1.1, you can use fmt.Println without having to know what code is being used to actually do the printing.
fmt.Println
You create a main() function in the third line of code, and you print the phrase "Hello, world!" by using Println from the fmt package you included. You don't need to understand how this works right now-just know that fmt.Println("") will print whatever is between the double quotes to the screen.
main()
Println
fmt.Println("")
After entering the listing, make sure you save the file. You should leave the file open in your text editor in case you have problems running it. The compiler will read only the saved content in the file.
The next step is to compile the file. Compiling is the process of converting human-readable code into machine-readable code. Use the cd command to...
cd
Dateiformat: ePUBKopierschutz: Adobe-DRM (Digital Rights Management)
Systemvoraussetzungen:
Das Dateiformat ePUB ist sehr gut für Romane und Sachbücher geeignet – also für „fließenden” Text ohne komplexes Layout. Bei E-Readern oder Smartphones passt sich der Zeilen- und Seitenumbruch automatisch den kleinen Displays an. Mit Adobe-DRM wird hier ein „harter” Kopierschutz verwendet. Wenn die notwendigen Voraussetzungen nicht vorliegen, können Sie das E-Book leider nicht öffnen. Daher müssen Sie bereits vor dem Download Ihre Lese-Hardware vorbereiten.Bitte beachten Sie: Wir empfehlen Ihnen unbedingt nach Installation der Lese-Software diese mit Ihrer persönlichen Adobe-ID zu autorisieren!
Weitere Informationen finden Sie in unserer E-Book Hilfe.