Learning Go

Go is rapidly becoming the preferred language for building web services. There are plenty of tutorials available that teach Go’s syntax to developers with experience in other programming languages. But tutorials aren’t enough. They don’t teach Go’s idioms, so developers end up recreating patterns th...

Descripción completa

Detalles Bibliográficos
Otros Autores: Bodner, Jon, author (author)
Formato: Libro electrónico
Idioma:Inglés
Publicado: O'Reilly Media, Inc 2021.
Edición:1st edition
Materias:
Ver en Biblioteca Universitat Ramon Llull:https://discovery.url.edu/permalink/34CSUC_URL/1im36ta/alma991009630985906719
Tabla de Contenidos:
  • Cover
  • Copyright
  • Table of Contents
  • Preface
  • Who Should Read This Book
  • Conventions Used in This Book
  • Using Code Examples
  • O'Reilly Online Learning
  • How to Contact Us
  • Acknowledgments
  • Chapter 1. Setting Up Your Go Environment
  • Installing the Go Tools
  • The Go Workspace
  • The go Command
  • go run and go build
  • Getting Third-Party Go Tools
  • Formatting Your Code
  • Linting and Vetting
  • Choose Your Tools
  • Visual Studio Code
  • GoLand
  • The Go Playground
  • Makefiles
  • Staying Up to Date
  • Wrapping Up
  • Chapter 2. Primitive Types and Declarations
  • Built-in Types
  • The Zero Value
  • Literals
  • Booleans
  • Numeric Types
  • A Taste of Strings and Runes
  • Explicit Type Conversion
  • var Versus :=
  • Using const
  • Typed and Untyped Constants
  • Unused Variables
  • Naming Variables and Constants
  • Wrapping Up
  • Chapter 3. Composite Types
  • Arrays-Too Rigid to Use Directly
  • Slices
  • len
  • append
  • Capacity
  • make
  • Declaring Your Slice
  • Slicing Slices
  • Converting Arrays to Slices
  • copy
  • Strings and Runes and Bytes
  • Maps
  • Reading and Writing a Map
  • The comma ok Idiom
  • Deleting from Maps
  • Using Maps as Sets
  • Structs
  • Anonymous Structs
  • Comparing and Converting Structs
  • Wrapping Up
  • Chapter 4. Blocks, Shadows, and Control Structures
  • Blocks
  • Shadowing Variables
  • Detecting Shadowed Variables
  • if
  • for, Four Ways
  • The Complete for Statement
  • The Condition-Only for Statement
  • The Infinite for Statement
  • break and continue
  • The for-range Statement
  • Labeling Your for Statements
  • Choosing the Right for Statement
  • switch
  • Blank Switches
  • Choosing Between if and switch
  • goto-Yes, goto
  • Wrapping Up
  • Chapter 5. Functions
  • Declaring and Calling Functions
  • Simulating Named and Optional Parameters
  • Variadic Input Parameters and Slices.
  • Multiple Return Values
  • Multiple Return Values Are Multiple Values
  • Ignoring Returned Values
  • Named Return Values
  • Blank Returns-Never Use These!
  • Functions Are Values
  • Function Type Declarations
  • Anonymous Functions
  • Closures
  • Passing Functions as Parameters
  • Returning Functions from Functions
  • defer
  • Go Is Call By Value
  • Wrapping Up
  • Chapter 6. Pointers
  • A Quick Pointer Primer
  • Don't Fear the Pointers
  • Pointers Indicate Mutable Parameters
  • Pointers Are a Last Resort
  • Pointer Passing Performance
  • The Zero Value Versus No Value
  • The Difference Between Maps and Slices
  • Slices as Buffers
  • Reducing the Garbage Collector's Workload
  • Wrapping Up
  • Chapter 7. Types, Methods, and Interfaces
  • Types in Go
  • Methods
  • Pointer Receivers and Value Receivers
  • Code Your Methods for nil Instances
  • Methods Are Functions Too
  • Functions Versus Methods
  • Type Declarations Aren't Inheritance
  • Types Are Executable Documentation
  • iota Is for Enumerations-Sometimes
  • Use Embedding for Composition
  • Embedding Is Not Inheritance
  • A Quick Lesson on Interfaces
  • Interfaces Are Type-Safe Duck Typing
  • Embedding and Interfaces
  • Accept Interfaces, Return Structs
  • Interfaces and nil
  • The Empty Interface Says Nothing
  • Type Assertions and Type Switches
  • Use Type Assertions and Type Switches Sparingly
  • Function Types Are a Bridge to Interfaces
  • Implicit Interfaces Make Dependency Injection Easier
  • Wire
  • Go Isn't Particularly Object-Oriented (and That's Great)
  • Wrapping Up
  • Chapter 8. Errors
  • How to Handle Errors: The Basics
  • Use Strings for Simple Errors
  • Sentinel Errors
  • Errors Are Values
  • Wrapping Errors
  • Is and As
  • Wrapping Errors with defer
  • panic and recover
  • Getting a Stack Trace from an Error
  • Wrapping Up
  • Chapter 9. Modules, Packages, and Imports.
  • Repositories, Modules, and Packages
  • go.mod
  • Building Packages
  • Imports and Exports
  • Creating and Accessing a Package
  • Naming Packages
  • How to Organize Your Module
  • Overriding a Package's Name
  • Package Comments and godoc
  • The internal Package
  • The init Function: Avoid if Possible
  • Circular Dependencies
  • Gracefully Renaming and Reorganizing Your API
  • Working with Modules
  • Importing Third-Party Code
  • Working with Versions
  • Minimum Version Selection
  • Updating to Compatible Versions
  • Updating to Incompatible Versions
  • Vendoring
  • pkg.go.dev
  • Additional Information
  • Publishing Your Module
  • Versioning Your Module
  • Module Proxy Servers
  • Specifying a Proxy Server
  • Private Repositories
  • Wrapping Up
  • Chapter 10. Concurrency in Go
  • When to Use Concurrency
  • Goroutines
  • Channels
  • Reading, Writing, and Buffering
  • for-range and Channels
  • Closing a Channel
  • How Channels Behave
  • select
  • Concurrency Practices and Patterns
  • Keep Your APIs Concurrency-Free
  • Goroutines, for Loops, and Varying Variables
  • Always Clean Up Your Goroutines
  • The Done Channel Pattern
  • Using a Cancel Function to Terminate a Goroutine
  • When to Use Buffered and Unbuffered Channels
  • Backpressure
  • Turning Off a case in a select
  • How to Time Out Code
  • Using WaitGroups
  • Running Code Exactly Once
  • Putting Our Concurrent Tools Together
  • When to Use Mutexes Instead of Channels
  • Atomics-You Probably Don't Need These
  • Where to Learn More About Concurrency
  • Wrapping Up
  • Chapter 11. The Standard Library
  • io and Friends
  • time
  • Monotonic Time
  • Timers and Timeouts
  • encoding/json
  • Use Struct Tags to Add Metadata
  • Unmarshaling and Marshaling
  • JSON, Readers, and Writers
  • Encoding and Decoding JSON Streams
  • Custom JSON Parsing
  • net/http
  • The Client
  • The Server
  • Wrapping Up.
  • Chapter 12. The Context
  • What Is the Context?
  • Cancellation
  • Timers
  • Handling Context Cancellation in Your Own Code
  • Values
  • Wrapping Up
  • Chapter 13. Writing Tests
  • The Basics of Testing
  • Reporting Test Failures
  • Setting Up and Tearing Down
  • Storing Sample Test Data
  • Caching Test Results
  • Testing Your Public API
  • Use go-cmp to Compare Test Results
  • Table Tests
  • Checking Your Code Coverage
  • Benchmarks
  • Stubs in Go
  • httptest
  • Integration Tests and Build Tags
  • Finding Concurrency Problems with the Race Checker
  • Wrapping Up
  • Chapter 14. Here There Be Dragons: Reflect, Unsafe, and Cgo
  • Reflection Lets Us Work with Types at Runtime
  • Types, Kinds, and Values
  • Making New Values
  • Use Reflection to Check If an Interface's Value Is nil
  • Use Reflection to Write a Data Marshaler
  • Build Functions with Reflection to Automate Repetitive Tasks
  • You Can Build Structs with Reflection, but Don't
  • Reflection Can't Make Methods
  • Only Use Reflection If It's Worthwhile
  • unsafe Is Unsafe
  • Use unsafe to Convert External Binary Data
  • unsafe Strings and Slices
  • unsafe Tools
  • Cgo Is for Integration, Not Performance
  • Wrapping Up
  • Chapter 15. A Look at the Future: Generics in Go
  • Generics Reduce Repetitive Code and Increase Type Safety
  • Introducing Generics in Go
  • Use Type Lists to Specify Operators
  • Generic Functions Abstract Algorithms
  • Type Lists Limit Constants and Implementations
  • Things That Are Left Out
  • Idiomatic Go and Generics
  • Further Futures Unlocked
  • Wrapping Up
  • Index
  • About the Author
  • Colophon.