Book description
Get started with Go and learn how to leverage its simplicity and flexibility to solve real-world problems and build practical software
Key Features
- Build a comprehensive foundation in Go and focus on developing real-world applications
- Explore the Go Standard Library and learn how to structure your code
- Learn how to efficiently interact with files, databases and REST APIs
Book Description
The Go Workshop will take the pain out of learning the Go programming language (also known as Golang). It is designed to teach you to be productive in building real-world software. Presented in an engaging, hands-on way, this book focuses on the features of Go that are used by professionals in their everyday work.
Each concept is broken down, clearly explained, and followed up with activities to test your knowledge and build your practical skills.
Your first steps will involve mastering Go syntax, working with variables and operators, and using core and complex types to hold data. Moving ahead, you will build your understanding of programming logic and implement Go algorithms to construct useful functions.
As you progress, you'll discover how to handle errors, debug code to troubleshoot your applications, and implement polymorphism using interfaces. The later chapters will then teach you how to manage files, connect to a database, work with HTTP servers and REST APIs, and make use of concurrent programming.
Throughout this Workshop, you'll work on a series of mini projects, including a shopping cart, a loan calculator, a working hours tracker, a web page counter, a code checker, and a user authentication system.
By the end of this book, you'll have the knowledge and confidence to tackle your own ambitious projects with Go.
What you will learn
- Understand Go syntax and use it to handle data and write functions
- Debug your Go code to troubleshoot development problems
- Safely handle errors and recover from panics
- Implement polymorphism by using interfaces
- Work with files and connect to external databases
- Create a HTTP client and server and work with a RESTful web API
- Use concurrency to design software that can multitask
- Use Go Tools to simplify development and improve your code
Who this book is for
The Go Workshop is designed for anyone who is new to Go. Whether you're beginning your journey as an aspiring developer, or are experienced with another programming language and want to branch out to something new, this book will get you on the right track. No prior programming experience is necessary.
Table of contents
-
Preface
-
About the Book
- About the Chapters
- Conventions
- Before You Begin
- Hardware and Software Recommendations for Windows with Docker
- Hardware and Software Recommendations for Windows without Docker
- Hardware and Software Recommendations for macOS with Docker
- Hardware and Software Recommendations for macOS without Docker
- Hardware and Software Recommendations for Linux
- Install the Go Compiler
- Install Git
- Install Visual Studio Code (Editor/IDE)
- Create a Test Application
- Install Docker
- Installing the Code Bundle
-
About the Book
-
1. Variables and Operators
-
Introduction
- What Does Go Look Like?
- Exercise 1.01: Using Variables, Packages, and Functions to Print Stars
- Activity 1.01 Defining and Printing
- Declaring Variables
- Declaring a Variable Using var
- Exercise 1.02: Declaring a Variable Using var
- Declaring Multiple Variables at Once with var
- Exercise 1.03: Declaring Multiple Variables at Once with var
- Skipping the Type or Value When Declaring Variables
- Exercise 1.04: Skipping the Type or Value When Declaring Variables
- Type Inference Gone Wrong
- Short Variable Declaration
- Exercise 1.05: Implementing Short Variable Declaration
- Declaring Multiple Variables with a Short Variable Declaration
- Exercise 1.06: Declaring Multiple Variables from a Function
- Using var to Declare Multiple Variables in One Line
- Non-English Variable Names
- Changing the Value of a Variable
- Exercise 1.07: Changing the Value of a Variable
- Changing Multiple Values at Once
- Exercise 1.08: Changing Multiple Values at Once
- Operators
- Exercise 1.09 Using Operators with Numbers
- Shorthand Operator
- Exercise 1.10: Implementing Shorthand Operators
- Comparing Values
- Exercise 1.11: Comparing Values
- Zero Values
- Exercise 1.12 Zero Values
- Value versus Pointer
- Getting a Pointer
- Exercise 1.13: Getting a Pointer
- Getting a Value from a Pointer
- Exercise 1.14: Getting a Value from a Pointer
- Function Design with Pointers
- Exercise 1.15: Function Design with Pointers
- Activity 1.02: Pointer Value Swap
- Constants
- Exercise 1.16: Constants
- Enums
- Scope
- Activity 1.03: Message Bug
- Activity 1.04: Bad Count Bug
- Summary
-
Introduction
-
2. Logic and Loops
-
Introduction
- if Statements
- Exercise 2.01: A Simple if Statement
- if else Statements
- Exercise 2.02: Using an if else Statement
- else if Statements
- Exercise 2.03: Using an else if Statement
- The Initial if Statement
- Exercise 2.04: Implementing the Initial if Statements
- Activity 2.01: Implementing FizzBuzz
- Expression switch Statements
- Exercise 2.05: Using a switch Statement
- Exercise 2.06: switch Statements and Multiple case Values
- Exercise 2.07: Expressionless switch Statements
- Loops
- Exercise 2.08: Using the for i Loop
- Exercise 2.09: Looping Over Arrays and Slices
- The range Loop
- Exercise 2.10: Looping Over a Map
- Activity 2.02: Looping Over Map Data Using range
- break and continue
- Exercise 2.11: Using break and continue to Control Loops
- Activity 2.03: Bubble Sort
- Summary
-
Introduction
- 3. Core Types
-
4. Complex Types
- Introduction
- Collection Types
-
Arrays
- Exercise 4.01: Defining an Array
- Comparing Arrays
- Exercise 4.02: Comparing Arrays
- Initializing Arrays Using Keys
- Exercise 4.03: Initializing an Array Using Keys
- Reading from an Array
- Exercise 4.04: Reading a Single Item from an Array
- Writing to an Array
- Exercise 4.05: Writing to an Array
- Looping an Array
- Exercise 4.06: Looping Over an Array Using a "for i" Loop
- Modifying the Contents of an Array in a Loop
- Exercise 4.07: Modifying the Contents of an Array in a Loop
- Activity 4.01: Filling an Array
-
Slice
- Exercise 4.08: Working with Slices
- Activity 4.02: Printing a User's Name Based on User Input
- Appending Multiple Items to a Slice
- Exercise 4.09: Appending Multiple Items to a Slice
- Activity 4.03: Creating a Locale Checker
- Creating Slices from Slices and Arrays
- Exercise 4.10: Creating Slices from a Slice
- Understanding Slice Internals
- Exercise 4.11: Using make to Control the Capacity of a Slice
- Background Behavior of Slices
- Exercise 4.12: Controlling Internal Slice Behavior
- Map Fundamentals
- Exercise 4.13: Creating, Reading, and Writing a Map
- Reading from Maps
- Exercise 4.14: Reading from a Map
- Activity 4.04: Slicing the Week
- Deleting Elements from a Map
- Exercise 4.15: Deleting an Element from a Map
- Activity 4.05: Removing an Element from a Slice
- Simple Custom Types
-
Structs
- Exercise 4.17: Creating Struct Types and Values
- Comparing Structs to Each Other
- Exercise 4.18: Comparing Structs to Each Other
- Struct Composition Using Embedding
- Exercise 4.19: Struct Embedding and Initialization
- Type Conversions
- Exercise 4.20: Numeric Type Conversion
- Type Assertions and interface{}
- Exercise 4.21: Type Assertion
- Type Switch
- Exercise 4.22: Type Switch
- Activity 4.06: Type Checker
- Summary
- 5. Functions
-
6. Errors
- Introduction
- What Are Errors?
- Error Handling Using Other Programming Languages
- Error Interface Type
- Panic
-
Recover
- Exercise 6.05: Recovering from a Panic
- Guidelines when working with Errors and Panic
- Activity 6.01: Creating a Custom Error Message for a Banking Application
- Activity 6.02: Validating a Bank Customer's Direct Deposit Submission
- Activity 6.03: Panic on Invalid Data Submission
- Activity 6.04: Preventing a Panic from Crashing the App
- Summary
- 7. Interfaces
- 8. Packages
- 9. Basic Debugging
-
10. About Time
- Introduction
- Making Time
- Comparing Time
- Duration Calculation
- Managing Time
-
Formatting Time
- Exercise 10.03: What Is the Time in Your Zone?
- Activity 10.01: Formatting a Date According to User Requirements
- Activity 10.02: Enforcing a Specific Format of Date and Time
- Activity 10.03: Measuring Elapsed Time
- Activity 10.04: Calculating the Future Date and Time
- Activity 10.05: Printing the Local Time in Different Time Zones
- Summary
- 11. Encoding and Decoding (JSON)
- 12. Files and Systems
- 13. SQL and Databases
-
14. Using the Go HTTP Client
- Introduction
- The Go HTTP Client and Its Uses
- Sending a Request to a Server
- Structured Data
-
Sending Data to a Server
- Exercise 14.03: Sending a Post Request to a Web Server Using the Go HTTP Client
- Uploading Files in a Post Request
- Exercise 14.04: Uploading a File to a Web Server via a Post Request
- Custom Request Headers
- Exercise 14.05: Using Custom Headers and Options with the Go HTTP Client
- Activity 14.02: Sending Data to a Web Server and Checking Whether the Data Was Received Using POST and GET
- Summary
- 15. HTTP Servers
- 16. Concurrent Work
- 17. Using Go Tools
- 18. Security
- 19. Special Features
-
Appendix
- 1. Variables and Operators
- 2. Logic and Loops
- 3. Core Types
- 4. Complex Types
- 5. Functions
- 6. Errors
- 7. Interfaces
- 8. Packages
- 9. Basic Debugging
- 10. About Time
- 11. Encoding and Decoding (JSON)
- 12. Files and Systems
- 13. SQL and Databases
- 14. Using the Go HTTP Client
- 15. HTTP Servers
- 16. Concurrent Work
- 17. Using Go Tools
- 18. Security
- 19. Special Features
- What Next?
Product information
- Title: The Go Workshop
- Author(s):
- Release date: December 2019
- Publisher(s): Packt Publishing
- ISBN: 9781838647940
You might also like
audiobook
Difficult Conversations
You have to talk with a colleague about a fraught situation, but you're worried that they'll …
audiobook
The Art of Leadership
Many people think leadership is a higher calling that resides exclusively with managers who practice or …
audiobook
Transformed
Help transform your business and innovate like the world's top tech companies! Transformed: Moving to the …
article
Facilitation in Action: Finding Your Authentic Training Style
Improve the Impact of Your Facilitation Facilitation is about mastering how to deliver an engaging learning …