Go Fundamentals: Gopher Guides

Book description

Start Writing Production-Ready Go Code Fast

Thousands of developers and teams want to start taking advantage of Go, the powerful language used in projects ranging from Kubernetes to Docker and Vault. Go Fundamentals is specifically designed to get you up-to-speed fast, to leverage your existing knowledge of other languages, and to help you avoid common mistakes made by Go newcomers.

Based on author Mark Bates's and Cory LaNou's pioneering Gopher Guides training curricula, this guide will allow you to quickly understand and use Go syntax, core features, and idioms. Reflecting Go through version 1.18--which includes Go's exciting new support for generics--this guide prepares you to write robust, reliable, well-performing production code right from the outset.

  • Learn how Go manages packages, modules, and dependencies

  • Apply Go basics, such as variable declaration, types, and control flow

  • Work effectively with collection types, iteration, functions, structs, and pointers

  • Understand Go Slices and use them properly

  • Write idiomatic Go, using principles such as embedding and composition

  • Expertly use concurrency to improve code performance

  • Create proper tests to quickly identify and fix problems

  • Write simpler, better code with generics and interfaces

  • Take advantage of channels, context, sync primatives, and other advanced features

Go is lightweight, simple, and perfect for modern cloud-native and microservices development, which is why Go developers are in such high demand. With this guide and six months' experience with any modern programming language, you'll have what you need to leap into Go programming.

Register your book for convenient access to downloads, updates, and/or corrections as they become available. See inside book for details.

Table of contents

  1. Cover Page
  2. About This eBook
  3. Halftitle Page
  4. Title Page
  5. Copyright Page
  6. Pearson’s Commitment to Diversity, Equity, and Inclusion
  7. Dedication Page
  8. Contents
  9. Foreword
  10. Preface
    1. How to Read This Book
    2. About the Examples
    3. Commands and Documentation
    4. Summary
  11. Acknowledgments
  12. About the Authors
  13. 1. Modules, Packages, and Dependencies
    1. Modules
    2. Packages
    3. Folders, Files, and Organization
    4. Importing Packages and Modules
    5. Dependencies
    6. Summary
  14. 2. Go Language Basics
    1. Go Language Overview
    2. Numbers
    3. Strings
    4. UTF-8
    5. Variables
    6. Constants
    7. Naming Identifiers
    8. Printing and Formatting
    9. Summary
  15. 3. Arrays, Slices, and Iteration
    1. List Types: Arrays and Slices
    2. How Slices Work
    3. Iteration
    4. Summary
  16. 4. Maps and Control Structures
    1. Maps
    2. If Statements
    3. Switch Statements
    4. Summary
  17. 5. Functions
    1. Function Definitions
    2. Variadic Arguments
    3. Deferring Function Calls
    4. Init
    5. Summary
  18. 6. Structs, Methods, and Pointers
    1. Structs
    2. Methods
    3. Pointers
    4. Nil Receivers
    5. Summary
  19. 7. Testing
    1. Testing Basics
    2. Code Coverage
    3. Table Driven Testing
    4. Running Tests
    5. Test Helpers
    6. Summary
  20. 8. Interfaces
    1. Concrete Types versus Interfaces
    2. Explicit Interface Implementation
    3. Implicit Interface Implementation
    4. Before Interfaces
    5. Using Interfaces
    6. Implementing io.Writer
    7. Multiple Interfaces
    8. Asserting Interface Implementation
    9. The Empty Interface
    10. The any Keyword
    11. Defining Interfaces
    12. Embedding Interfaces
    13. Type Assertion
    14. Assertions through Switch
    15. Using Assertions
    16. Summary
  21. 9. Errors
    1. Errors as Values
    2. The error Interface
    3. Handling Errors
    4. Panic
    5. Raising a Panic
    6. Recovering from a Panic
    7. Don’t Panic
    8. Maps
    9. Pointers
    10. Interfaces
    11. Custom Errors
    12. Wrapping and Unwrapping Errors
    13. Unwrapping Errors
    14. Unwrapping Custom Errors
    15. To Wrap or Not To Wrap
    16. Errors As/Is
    17. As
    18. Is
    19. Stack Traces
    20. Summary
  22. 10. Generics
    1. What Are Generics?
    2. Summary
  23. 11. Channels
    1. Concurrency and Parallelism
    2. Go’s Concurrency Model
    3. Communicating with Channels
    4. Unidirectional Channels
    5. Closing Channels
    6. Buffered Channels
    7. Capturing System Signals with Channels
    8. Summary
  24. 12. Context
    1. The Context Interface
    2. Context Rules
    3. Context Nodal Hierarchy
    4. Context Values
    5. Problems with String Keys
    6. Securing Context Keys and Values
    7. Cancellation Propagation with Contexts
    8. Timeouts and Deadlines
    9. Context Errors
    10. Listening for System Signals with Context
    11. Summary
  25. 13. Synchronization
    1. Waiting for Goroutines with a WaitGroup
    2. Error Management with Error Groups
    3. Data Races
    4. Synchronizing Access with a Mutex
    5. Performing Tasks Only Once
    6. Summary
  26. 14. Working with Files
    1. Directory Entries and File Information
    2. Walking Directories
    3. Skipping Directories and Files
    4. Creating Directories and Subdirectories
    5. File Path Helpers
    6. Creating Multiple Directories
    7. Creating Files
    8. Fixing the Walk Tests
    9. Appending to Files
    10. Reading Files
    11. Beware of Windows
    12. The FS Package
    13. Using the FS Interface
    14. Mocking a File System
    15. Embedding Files
    16. Summary
  27. Index
  28. Code Snippets

Product information

  • Title: Go Fundamentals: Gopher Guides
  • Author(s): Mark Bates, Cory LaNou
  • Release date: November 2022
  • Publisher(s): Addison-Wesley Professional
  • ISBN: 9780137918416