Chapter 5

Functions

Function declarations, recursion, defer, and closures

✓ Write idiomatic functions ✓ Handle errors properly ✓ Use defer
1
Defer1
Defer1 demonstrates a deferred call being invoked during a panic.
p.150 +15 XP intermediate
2
Defer2
Defer2 demonstrates a deferred call to runtime.Stack during a panic.
p.151 +15 XP intermediate
3
Fetch
Fetch saves the contents of a URL into a local file.
p.148 +15 XP intermediate
4
Findlinks1
Findlinks1 prints the links in an HTML document read from standard input.
p.122 +15 XP intermediate
5
Findlinks2
Findlinks2 does an HTTP GET on each URL, parses the result as HTML, and prints the links within it. Usage: findlinks url ...
p.125 +15 XP intermediate
6
Findlinks3
Findlinks3 crawls the web, starting with the URLs on the command line.
p.139 +15 XP intermediate
7
Links
Package links provides a link-extraction function.
p.138 +15 XP intermediate
8
Outline
Outline prints the outline of an HTML document tree.
p.123 +15 XP intermediate
9
Outline2
Outline prints the outline of an HTML document tree.
p.133 +15 XP intermediate
10
Squares
The squares program demonstrates a function value with state.
p.135 +15 XP intermediate
11
Sum
The sum program demonstrates a variadic function.
p.142 +15 XP intermediate
12
Title1
Title1 prints the title of an HTML document specified by a URL.
p.144 +15 XP intermediate
13
Title2
Title2 prints the title of an HTML document specified by a URL. It uses defer to simplify closing the response body stream.
p.145 +15 XP intermediate
14
Title3
Title3 prints the title of an HTML document specified by a URL.
p.153 +15 XP intermediate
15
Toposort
The toposort program prints the nodes of a DAG in topological order.
p.136 +15 XP intermediate
16
Trace
The trace program uses defer to add entry/exit diagnostics to a function.
p.146 +15 XP intermediate
17
Wait
The wait program waits for an HTTP server to start responding.
p.130 +15 XP intermediate