What you will learn in Go by Example
Programmer's guide to idiomatic and testable code
Chapter by chapter
Concepts explained in this book
- contextcontext.Context is a Go standard-library interface that carries cancellation signals, deadlines, and request-scoped values across call boundaries.
- testA test case is a defined test scenario consisting of inputs, execution conditions, and expected behavior or results.
- pipelineA pipeline is an ordered sequence of connected processing stages in which results from one stage are passed to subsequent stages.
- command-line argumentA command-line argument is a string value supplied to a program by the operating system when the program starts.
- middlewareMiddleware is a software pattern in which a component wraps a handler or processing component to add behavior before, after, or around the wrapped component's execution.
- io.Writerio.Writer is a Go interface whose Write method accepts a byte sequence and returns the number of bytes written and an error.
- iteratorAn iterator is an abstraction that lets a consumer retrieve values from a sequence one at a time through a standardized interface.
- type assertionA runtime type assertion is a Go expression that checks and retrieves the concrete value represented by an interface value at run time.
- closureA closure is a function that retains access to variables in its surrounding lexical scope after the enclosing function returns.
- benchmarkA benchmark is a repeatable performance measurement that runs a piece of code, usually many times, to assess its execution characteristics.
- handlerA handler is a software component that receives an operation or request and produces the corresponding processing result.
- channelA channel is a typed Go communication conduit through which goroutines send and receive values while synchronizing.
- subtestA subtest is an independently named test executed as part of a parent test and reported separately.
- value parserA value parser is a function that converts a string flag value to a specified Go type, assigns the result to a variable, and reports parsing errors.
- goroutineA goroutine is a lightweight Go execution unit that runs a function concurrently with other goroutines.
- GoGo is a statically typed, compiled programming language designed for simplicity, efficient execution, and reliable software development.
- task cancellationA cancellation signal is an indication that an ongoing operation should stop because it is no longer needed or cannot continue.
- testabilityTestability is the degree to which software can be tested effectively and independently.
- implicit interface satisfactionAn implicit interface is a Go interface that a type satisfies automatically by implementing all of the interface's methods without an explicit declaration.
- ShortenerA shortener service is a service that converts URLs into shorter keys and resolves those keys back to URLs.
- zero valueA zero value is the default value assigned to a Go variable when no explicit initializer is provided.
- database/sqldatabase/sql is Go's standard library package that provides a database-independent API for working with SQL databases.
- concurrencyConcurrency is the ability to structure a program so that multiple execution activities can make progress during overlapping periods.
- flag.FlagSetflag.FlagSet is a Go flag package type that defines a set of command-line flags and manages their parsing and usage behavior.
- database driverA database driver is software that implements a database access interface for communicating with a particular database technology.
- http.RoundTripperhttp.RoundTripper is a Go interface whose RoundTrip method executes a single HTTP transaction and returns the response or an error.
- memory allocationA memory allocation is a reservation of heap memory made during program execution, commonly counted per operation in performance measurements.
- table-driven testTable-driven testing is a testing technique that represents multiple test cases as data and executes a common test procedure for each case.
- referenceA pointer is a Go value that contains the memory address of another value and permits indirect access to it.
- strings.Builderstrings.Builder is a Go standard-library type that efficiently accumulates bytes or strings and converts the accumulated data to a string.
- errors.Iserrors.Is is a Go standard-library function that reports whether an error or any error in its wrapping chain matches a target error.
- correlation idA trace ID is an identifier that correlates processing and log records belonging to the same request or distributed operation.
- circular dependencyAn import cycle is a circular dependency among Go packages that prevents the package import graph from being acyclic.
- httptestThe httptest package is Go's standard-library package for testing HTTP clients and servers with utilities such as in-memory test servers, requests, and responses.
- standard libraryA standard library is a collection of reusable modules, types, functions, APIs, and other facilities distributed with a programming language implementation or platform.
- compositionComposition is a design approach that builds larger abstractions by combining smaller components rather than inheriting implementation from a base type.
- race conditionA race condition is a concurrency defect in which program behavior depends on the timing or ordering of operations accessing shared state.
- optional interfaceAn optional interface is an interface whose support a type may provide to expose additional behavior without being required by the base contract.
- flag packageThe flag package is Go's standard package for parsing command-line flags and defining their names, defaults, and value handling.
- polymorphismPolymorphism is the ability to treat instances of different types through a shared type or interface while preserving type-specific behavior.
- dispatcherA dispatcher is a pipeline stage that launches concurrent workers to send requests and collect their results.
- t.Errorftesting.T.Errorf records a formatted test failure while allowing the calling test function to continue.
- concrete typeA concrete type is a non-interface Go type that specifies values with an underlying representation and may have methods.
- parsingParse is a book-specific function that parses a URL into a URL value and reports an error when the URL lacks a scheme.
- errors.Aserrors.As is a Go standard-library function that searches an error chain for a value assignable to a specified error type and stores the result.
- connection poolingA connection pool is a managed collection of reusable network connections maintained to avoid repeatedly establishing new connections.
- lockingLocking is a concurrency-control technique that restricts access to a shared resource or protected operation to prevent conflicting concurrent access.
- aspectInterceptor is a book-specific wrapper type that intercepts response-writing behavior while retaining access to the wrapped response writer.
- http.Serverhttp.Server is Go's HTTP server type that accepts network connections and dispatches requests to a configured handler.
- multi-tier applicationA layered package structure is an organization in which packages depend only on packages in lower layers of the structure.
- idiomatic coding styleA programming idiom is a customary way of expressing a solution or structure in a particular programming language.
- style guideA programming convention is a commonly accepted practice for organizing or expressing code within a language community.
- http.ResponseWriterhttp.ResponseWriter is the Go HTTP interface through which a handler constructs an HTTP response and accesses connection-related response behavior.
- example testAn example test is a Go test function whose output serves both as an executable check and as documentation for an example of using an API.
- go testgo test is the Go command that builds and runs tests for Go packages.
- yield functionA yield function is a consumer-provided callback that receives one iterator value and returns a boolean indicating whether iteration should continue.
- Fatalftesting.T.Fatalf records a formatted test failure and stops execution of the calling test function.
- TextMarshalerTextMarshaler is a Go interface for types that can encode themselves as text.
- flag.Valueflag.Value is a Go interface for parsing a command-line flag string and assigning the resulting value to an associated variable.
- struct embeddingField embedding is the inclusion of an anonymous field in a Go struct so the embedded field and its members can be promoted.
- packageA Go package is a collection of Go source files that provides a namespace and compilation unit.
- command-line toolA command-line tool is a software program operated through textual commands in a shell or terminal.
- testing.B.Looptesting.B.Loop is a Go testing package method that executes benchmark iterations while preventing compiler optimizations from invalidating the measured code.
- dependency injectionDependency injection is a software design technique in which required dependencies are supplied to a component from outside rather than created internally.
- sql.DBsql.DB is the database/sql concrete type that provides database operations while managing a pool of database connections.
- UnwrapUnwrap is a method that exposes the underlying wrapped object or response writer for access to its additional behavior.
- io.Readerio.Reader is a Go interface whose Read method fills a caller-provided byte slice with incoming data and reports the amount read and any error.
- consumer-driven interfaceA consumer-driven interface is an interface declared around the specific operations required by its consuming client rather than around all operations of an implementation.
- stutteringStuttering is repetitive naming in which a package-qualified identifier redundantly repeats information already conveyed by the package name.
- error chainAn error chain is a linked sequence of wrapped Go error values that preserves an underlying cause and added context.
- init functionAn init function is a special Go function that runs automatically during package initialization before program execution begins.
- testing.T.Runtesting.T.Run is a Go testing API method that executes a named subtest and reports its result independently.
- RESTREST is an architectural approach for designing networked resources and interactions through uniform operations, commonly over HTTP.
- interface embeddingInterface embedding is the inclusion of one interface's method set in another interface by naming the embedded interface.
- URLA URL is a structured identifier for locating a resource through a network-access scheme, host, and optional path.
- throttlerA throttler is a concurrency component that spaces messages or operations by delaying their forwarding or execution.
- serverAn HTTP server is software that accepts and processes Hypertext Transfer Protocol requests and returns responses.
- producerA producer is a pipeline stage that creates and delivers messages to a subsequent stage.
- iter.Seqiter.Seq is Go's generic standard-library function type representing a push iterator whose yield callback receives values and returns whether iteration should continue.
- net/http packageThe http package is Go's standard-library package providing HTTP client and server implementations and related types.
- go:embed directiveFile embedding is the Go compiler feature that incorporates external file contents into a program's variables and compiled binary.
- http.HandlerFunchttp.HandlerFunc is a Go function type that adapts a function with an HTTP handler signature to the http.Handler interface.
- push iteratorA push iterator is an iteration abstraction in which a producer invokes a consumer with each successive value rather than having the consumer request values.
- custom flag parserA custom flag parser is program logic that interprets command-line flag names and values and assigns the parsed values to configuration fields.
- SQLiteSQLite is an embedded relational database engine that stores data in a local file or in memory without requiring a separate server process.
- StringA Go string is an immutable sequence of bytes whose contents can be represented without copying when sliced.
- help messageA usage message is command-line help text describing a program's available options, types, defaults, and invocation syntax.
- io.Copyio.Copy is a Go standard-library function that copies bytes from an io.Reader to an io.Writer and returns the number of bytes copied and any error.
- SQLAn SQL query is a statement expressed in SQL that requests or modifies data in a relational database.
- dependencyA software dependency is an external component or runtime resource required by a program to function.
- rwmutexRWMutex is a Go synchronization type that permits concurrent read access while allowing only one writer at a time.
- integration testAn integration test verifies behavior involving interactions between a program and external systems or components.
- variadic argumentsA variadic function is a function that accepts a variable number of arguments through a variadic parameter represented inside the function as a slice.
- http.Transporthttp.Transport is a Go HTTP transport implementation that performs request transmission and maintains a pool of reusable network connections.
- call by valuePass-by-value is a parameter-passing semantics in which a function receives a copy of each argument's value.
- command-line parsingA command-line parser is software that interprets command-line arguments and flags according to a defined syntax.
- http.Responsehttp.Response is the Go standard-library type representing an HTTP response, including its status, headers, and body.
- http.NewRequesthttptest.NewRequest is a Go standard-library function that constructs an HTTP request for use in server tests and panics if its method or target is invalid.
- FlagSet.VarFlagSet.Var is a method that registers a named command-line flag backed by a value implementing the flag.Value interface.
- roundTripperFuncA roundTripperFunc is a function type that adapts a function with a RoundTripper-compatible signature into a RoundTripper implementation.
- backing arrayA backing array is the array that stores the elements referenced by a Go slice.
- driver.Valuerdriver.Valuer is a Go interface implemented by types that convert themselves into values accepted by a database driver.
- error wrappingError wrapping is the practice of adding contextual information to an error while preserving the original error for later inspection.
- range loopA for-range loop is a Go loop construct that iterates over values produced by a rangeable expression, including supported iterator functions.
- %w error verbThe %w error verb is a Go formatting directive that records an operand as the wrapped cause of a returned error.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
