Chapter 5. Functions in Go

One of Go's syntactical tour de force is via its support for higher-order functions as is found in dynamic languages such as Python or Ruby. As we will see in this chapter, a function is also a typed entity with a value that can be assigned to a variable. In this chapter, we are going to explore functions in Go covering the following topics:

  • Go functions
  • Passing parameter values
  • Anonymous functions and closures
  • Higher-order functions
  • Error signaling handling
  • Deferring function calls
  • Function panic and recovery

Go functions

In Go, functions are first-class, typed programming elements. A declared function literal always has a type and a value (the defined function itself) and can optionally be bound to a named identifier. Because ...

Get Go: Design Patterns for Real-World Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.