Go was created by Robert Griesemer, Rob Pike, and Ken Thompson to be an expressive and efficient language for writing readable and robust programs. Since its announcement in 2009, users of traditional, compiled languages have found Go’s simplicity, high-quality libraries, and straightforward tools to be a refreshing change. Go has also been winning converts from users of dynamic languages—those who appreciate how its lightweight type system makes their code safer and faster.
The first chapter is a tutorial on the basic constructs of Go, introduced through example programs for file I/O and text processing, simple graphics, and web clients and servers.
Early chapters cover the structural elements of a Go program: its syntax, basic and composite data types, functions, and error handling. The examples illustrate many standard packages, how to create new ones, and how to build, test, and manage projects using the go tool.
The chapters on methods and interfaces introduce Go’s unusual approach to object-oriented programming, including the key principles of encapsulation and composition, as well as Go’s distinctive notion of implicitly satisfied interfaces.
Two chapters on concurrency present in-depth approaches to this important topic. The first covers the basic mechanisms of goroutines and channels and the style of communicating sequential processes for which Go is renowned. The second covers more traditional aspects of using concurrency with shared variables. These chapters assume no prior knowledge of concurrency, so they provide an excellent tutorial for programmers who would like to understand it better.
The final two chapters explore lower-level features of Go. One covers the art of metaprogramming using reflection. The other shows how to use the unsafe package to step outside the type system in a controlled way for special situations, and how to use the cgo tool to create Go bindings for C libraries.
The book features hundreds of interesting and practical examples of idiomatic Go code that cover the whole language, its most important libraries, and a wide range of applications. Source code will be freely available for download from the book's companion website (upon publication) and may be conveniently fetched, built, and installed using the go get command.
Table of contents
- 1. Tutorial
- 2. Program Structure
- 3. Basic Data Types
- 4. Composite Types
- 5. Functions
- 6. Methods
- 7.1 Interfaces as Contracts
- 7.2 Interface Types
- 7.3 Interface Satisfaction
- 7.4 Parsing Flags with flag.Value
- 7.5 Interface Values
- 7.6 Sorting with sort.Interface
- 7.7 The http.Handler Interface
- 7.8 The error Interface
- 7.9 Example: Expression Evaluator
- 7.10 Type Assertions
- 7.11 Discriminating Errors with Type Assertions
- 7.12 Querying Behaviors with Interface Type Assertions
- 7.13 Type Switches
- 7.14 Example: Token-Based XML Decoding
- 7.15 A Few Words of Advice
- 8. Goroutines and Channels
- 9. Concurrency with Shared Variables
- 10. Packages and the Go Tool
- 11. Testing
- 12.1 Why Reflection?
- 12.2 reflect.Type and reflect.Value
- 12.3 Display, a Recursive Value Printer
- 12.4 Example: Encoding S-Expressions
- 12.5 Setting Variables with reflect.Value
- 12.6 Example: Decoding S-Expressions
- 12.7 Accessing Struct Field Tags
- 12.8 Displaying the Methods of a Type
- 12.9 A Word of Caution
- 13. Low-Level Programming
- Title: The Go Programming Language
- Release date: October 2015
- Publisher(s): Addison-Wesley Professional
- ISBN: 9780134190570
You might also like
Go in Action
Summary Go in Action introduces the Go language, guiding you from inquisitive developer to Go guru. …
Clean Code: A Handbook of Agile Software Craftsmanship
Even bad code can function. But if code isn't clean, it can bring a development organization …
Get Programming with Go
Summary Get Programming with Go introduces you to the powerful Go language without confusing jargon or …
Expanded Edition (August 2018) Updated with Design Patterns episodes from the Clean Code series from Clean …