gopl

module
v0.0.0-...-4489971 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2024 License: MIT

README

gopl

Exercises from The Go Programming Language

Directories

Path Synopsis
chapter01
ch01ex01
Ch01ex01 modifies Echo to print the name of the command that invoked it and all its arguments.
Ch01ex01 modifies Echo to print the name of the command that invoked it and all its arguments.
ch01ex02
Ch01ex02 modifies Echo to print the index and value of each argument, one per line.
Ch01ex02 modifies Echo to print the index and value of each argument, one per line.
ch01ex04
Ch01ex04 modifies dup2 to print the names of files in which duplicates occur.
Ch01ex04 modifies dup2 to print the names of files in which duplicates occur.
ch01ex05
Ch01ex05 changes the palette to green on black.
Ch01ex05 changes the palette to green on black.
ch01ex06
Ch01ex06 produces Lissajous images in multiple colours.
Ch01ex06 produces Lissajous images in multiple colours.
ch01ex07
Ch01ex07 uses io.copy instead of ioutil.ReadAll for fetch.
Ch01ex07 uses io.copy instead of ioutil.ReadAll for fetch.
ch01ex08
Ch01ex08 modifies fetch to add the prefix http:// to the URL argument if it is missing.
Ch01ex08 modifies fetch to add the prefix http:// to the URL argument if it is missing.
ch01ex09
Ch01ex09 modifies fetch to also print the HTTP status code.
Ch01ex09 modifies fetch to also print the HTTP status code.
ch01ex10
Ch01ex10 modifies fetchall to print the output to a file.
Ch01ex10 modifies fetchall to print the output to a file.
ch01ex12
Ch01ex12 modifies the Lissajous server to read parameter values from the URL.
Ch01ex12 modifies the Lissajous server to read parameter values from the URL.
chapter02
ch02ex01/tempconv
Package tempconv performs Celsius, Fahrenheit and Kelvin conversions.
Package tempconv performs Celsius, Fahrenheit and Kelvin conversions.
ch02ex02
Ch02ex02 is a general-purpose unit-conversion program.
Ch02ex02 is a general-purpose unit-conversion program.
ch02ex03
Package ch02ex03 modifies popcount using a loop instead of a single expression.
Package ch02ex03 modifies popcount using a loop instead of a single expression.
ch02ex04
Package ch02ex04 modifies popcount using shifting.
Package ch02ex04 modifies popcount using shifting.
ch02ex05
Package ch02ex05 modifies popcount using x&(x-1).
Package ch02ex05 modifies popcount using x&(x-1).
chapter03
ch03ex01
Ch03ex01 modifies surface to skip invalid polgyons.
Ch03ex01 modifies surface to skip invalid polgyons.
ch03ex02
Ch03ex02 modifies surface to produce different surfaces.
Ch03ex02 modifies surface to produce different surfaces.
ch03ex03
Ch03ex03 modifies surface to colour peaks red and valleys blue.
Ch03ex03 modifies surface to colour peaks red and valleys blue.
ch03ex04
Ch03ex04 provides a web server that computes sufaces and writes SVG data to the client.
Ch03ex04 provides a web server that computes sufaces and writes SVG data to the client.
ch03ex05
Ch03ex05 generates a full-colour mandelbrot set using interpolated rainbow colours.
Ch03ex05 generates a full-colour mandelbrot set using interpolated rainbow colours.
ch03ex06
Ch03ex06 generates a full-colour mandelbrot set with supersampling.
Ch03ex06 generates a full-colour mandelbrot set with supersampling.
ch03ex07
Ch03ex07 generates a Newton fractal for z^4 - 1 = 0 with supersampling.
Ch03ex07 generates a Newton fractal for z^4 - 1 = 0 with supersampling.
ch03ex08/bigFloat
BigFloat renders the Mandelbrot fractal using math/big.Float.
BigFloat renders the Mandelbrot fractal using math/big.Float.
ch03ex08/bigRat
BigRat renders the Mandelbrot fractal using math/big.Rat.
BigRat renders the Mandelbrot fractal using math/big.Rat.
ch03ex08/complex128
Complex128 renders the Mandelbrot fractal using complex128.
Complex128 renders the Mandelbrot fractal using complex128.
ch03ex08/complex64
Complex64 renders the Mandelbrot fractal using complex64.
Complex64 renders the Mandelbrot fractal using complex64.
ch03ex09
Ch03ex09 implements a web server that renders fractals and writes image data to client.
Ch03ex09 implements a web server that renders fractals and writes image data to client.
ch03ex10
Ch03ex10 is a non-recursive version of comma using bytes.Buffer instead of string concatenation.
Ch03ex10 is a non-recursive version of comma using bytes.Buffer instead of string concatenation.
ch03ex11
Ch03ex11 extends comma to work with floating-point numbers and an optional sign.
Ch03ex11 extends comma to work with floating-point numbers and an optional sign.
ch03ex12
Ch03ex12 tests whether two strings are anagrams of each other.
Ch03ex12 tests whether two strings are anagrams of each other.
ch03ex13
Ch03ex13 declares constants for KB, MB etc.
Ch03ex13 declares constants for KB, MB etc.
chapter04
ch04ex01
Ch04ex01 counts the number of bits that are different in two SHA256 hashes.
Ch04ex01 counts the number of bits that are different in two SHA256 hashes.
ch04ex02
Ch04ex02 prints the SHA256 hash of its standard input, but supports command line flags for SHA384 or SHA512 hashes as well.
Ch04ex02 prints the SHA256 hash of its standard input, but supports command line flags for SHA384 or SHA512 hashes as well.
ch04ex03
Ch04ex03 reverses an array using a pointer instead of a slice.
Ch04ex03 reverses an array using a pointer instead of a slice.
ch04ex04
Ch04ex04 implements a single pass rotate function.
Ch04ex04 implements a single pass rotate function.
ch04ex05
Ch04ex05 implements an in-place function that eliminates adjacent duplicates in a []string slice.
Ch04ex05 implements an in-place function that eliminates adjacent duplicates in a []string slice.
ch04ex06
Ch04ex06 squashes adjacent Unicode spaces in a UTF-8-encoded byte slice.
Ch04ex06 squashes adjacent Unicode spaces in a UTF-8-encoded byte slice.
ch04ex07
Ch04ex07 reverses a byte slice representing a UTF-8 string in-place.
Ch04ex07 reverses a byte slice representing a UTF-8 string in-place.
ch04ex08
Ch04ex08 adds Unicode category counts to the charcount program.
Ch04ex08 adds Unicode category counts to the charcount program.
ch04ex09
Ch04ex09 counts the frequency of each word in an input text file.
Ch04ex09 counts the frequency of each word in an input text file.
ch04ex10/github
Package github provides a Go API for the GitHub issue tracker.
Package github provides a Go API for the GitHub issue tracker.
ch04ex10/issues
Issues prints a table of GitHub issues matching the search terms.
Issues prints a table of GitHub issues matching the search terms.
ch04ex11/ghissues
Ghissues lets you create, read, update and close GitHub issues from the command line.
Ghissues lets you create, read, update and close GitHub issues from the command line.
ch04ex11/github
Package github provides a Go API for the GitHub issue tracker.
Package github provides a Go API for the GitHub issue tracker.
ch04ex12
Ch04ex12 builds an index of xkcd transcripts that can be queried.
Ch04ex12 builds an index of xkcd transcripts that can be queried.
ch04ex13
Ch04ex13 queries the IMDb API at voku.xyz for movie titles and fetches the poster for the movie supplied as a command line argument.
Ch04ex13 queries the IMDb API at voku.xyz for movie titles and fetches the poster for the movie supplied as a command line argument.
ch04ex14/ghbrowser
Ghbrowser runs an HTTP server to browse the issues of a GitHub repository.
Ghbrowser runs an HTTP server to browse the issues of a GitHub repository.
ch04ex14/github
Package github provides a Go API for the GitHub issue tracker.
Package github provides a Go API for the GitHub issue tracker.
chapter05
ch05ex01
Ch05ex01 is a version of findlinks with recursive child traversal instead of a loop.
Ch05ex01 is a version of findlinks with recursive child traversal instead of a loop.
ch05ex02
Ch05ex02 builds a mapping from element names to the number of occurrences of that element in an HTML tree.
Ch05ex02 builds a mapping from element names to the number of occurrences of that element in an HTML tree.
ch05ex03
Ch05ex03 traverses and HTML tree and prints the content of all text nodes (except contents of script and style elements).
Ch05ex03 traverses and HTML tree and prints the content of all text nodes (except contents of script and style elements).
ch05ex04
Ch05ex04 extracts image, script and style sheet links.
Ch05ex04 extracts image, script and style sheet links.
ch05ex05
Ch05ex05 fetches the document from the URL specified as an argument and prints word and image count.
Ch05ex05 fetches the document from the URL specified as an argument and prints word and image count.
ch05ex06
Ch05ex06 modifies the corner function of the surface program to use named results and a bare return statement.
Ch05ex06 modifies the corner function of the surface program to use named results and a bare return statement.
ch05ex07
Ch05ex07 is an HTML pretty printer.
Ch05ex07 is an HTML pretty printer.
ch05ex08
Ch05ex08 finds the first element with the given ID in the supplied HTML documents.
Ch05ex08 finds the first element with the given ID in the supplied HTML documents.
ch05ex09
Ch05ex09 expands each substring $foo to f(foo).
Ch05ex09 expands each substring $foo to f(foo).
ch05ex10
Ch05ex10 rewrites topoSort to use maps instead of slices and eliminates the initial sort.
Ch05ex10 rewrites topoSort to use maps instead of slices and eliminates the initial sort.
ch05ex11
Ch05ex11 extends topoSort to report cycles.
Ch05ex11 extends topoSort to report cycles.
ch05ex12
Ch05ex12 turns startElement and endElement into anonymous functions sharing a variable local to the outline function.
Ch05ex12 turns startElement and endElement into anonymous functions sharing a variable local to the outline function.
ch05ex13/grablinks
Grablinks makes local copies of the pages it crawls, creating directories as necessary, except for pages from different domains.
Grablinks makes local copies of the pages it crawls, creating directories as necessary, except for pages from different domains.
ch05ex13/links
Package links provides a link-extraction function.
Package links provides a link-extraction function.
ch05ex14
Ch05ex14 uses breadthFirst to traverse other structures.
Ch05ex14 uses breadthFirst to traverse other structures.
ch05ex15
Ch05ex15 implements variadic max and min functions.
Ch05ex15 implements variadic max and min functions.
ch05ex16
Ch05ex16 implements strings.Join as a variadic function.
Ch05ex16 implements strings.Join as a variadic function.
ch05ex17
Ch05ex17 implements a variadic function that extracts HTML elements by name from an HTML document.
Ch05ex17 implements a variadic function that extracts HTML elements by name from an HTML document.
ch05ex18
Ch05ex18 saves the contents of a URL into a local file, using defer to close the file.
Ch05ex18 saves the contents of a URL into a local file, using defer to close the file.
ch05ex19
Ch05ex19 implements a function without return statement that returns a non-zero value.
Ch05ex19 implements a function without return statement that returns a non-zero value.
Chapter06 implements exercises 6.1 to 6.4.
Chapter06 implements exercises 6.1 to 6.4.
ch06ex05
Ch06ex06 uses a platform-specific word sizes for the bitset implementation.
Ch06ex06 uses a platform-specific word sizes for the bitset implementation.
ch06ex05/intset
Package intset provides a set of integers based on a bit vector, using a platform-specific word size.
Package intset provides a set of integers based on a bit vector, using a platform-specific word size.
intset
Package intset provides a set of integers based on a bit vector.
Package intset provides a set of integers based on a bit vector.
chapter07
ch07ex01
Ch07ex01 implements writers that count words and lines.
Ch07ex01 implements writers that count words and lines.
ch07ex02
Ch07ex02 implements a function that returns a writer wrapping another writer and an int64 representing the number of bytes written to the writer at any time.
Ch07ex02 implements a function that returns a writer wrapping another writer and an int64 representing the number of bytes written to the writer at any time.
ch07ex03/treesort
Package treesort provides insertion sort using an unbalanced binary tree.
Package treesort provides insertion sort using an unbalanced binary tree.
ch07ex04
Ch07ex04 implements NewReader and a simple string reader to use with the HTML parser from exercise 5.2.
Ch07ex04 implements NewReader and a simple string reader to use with the HTML parser from exercise 5.2.
ch07ex05
Ch07ex05 implements a LimitReader.
Ch07ex05 implements a LimitReader.
ch07ex06
Ch07ex06 prints the value of its -temp (temperature) flag, which can be in Celsius, Fahrenheit or Kelvin.
Ch07ex06 prints the value of its -temp (temperature) flag, which can be in Celsius, Fahrenheit or Kelvin.
ch07ex06/tempconv
Package tempconv performs Celsius, Fahrenheit, and Kelvin temperature computations.
Package tempconv performs Celsius, Fahrenheit, and Kelvin temperature computations.
ch07ex08
Ch07ex08 tests the statefulsort implementation for music tracks.
Ch07ex08 tests the statefulsort implementation for music tracks.
ch07ex08/statefulsort
Package statefulsort provides a sort interface to sort elements with a mutable order in which element fields are taken into account for sorting.
Package statefulsort provides a sort interface to sort elements with a mutable order in which element fields are taken into account for sorting.
ch07ex08/track
Package track provides Track, an implementation of the statefulsort interface that represents a music track on an album.
Package track provides Track, an implementation of the statefulsort interface that represents a music track on an album.
ch07ex09
Ch07ex09 implements a web server with a sortable table that keeps track of state.
Ch07ex09 implements a web server with a sortable table that keeps track of state.
ch07ex09/track
Package track provides Track, an implementation of the statefulsort interface that represents a music track on an album.
Package track provides Track, an implementation of the statefulsort interface that represents a music track on an album.
ch07ex10
Ch07ex10 implements a palindrome checker taking advantage of sort.Interface.
Ch07ex10 implements a palindrome checker taking advantage of sort.Interface.
ch07ex11
Ch07ex11 adds CRUD functionality to a simple e-commerce server.
Ch07ex11 adds CRUD functionality to a simple e-commerce server.
ch07ex12
Ch07ex12 has the list endpoint rewritten to use html/template.
Ch07ex12 has the list endpoint rewritten to use html/template.
ch07ex13
Ch07ex13 tests an implementation of the Expr interface with an additional pretty printer method Print().
Ch07ex13 tests an implementation of the Expr interface with an additional pretty printer method Print().
ch07ex13/eval
Package eval provides an expression evaluator.
Package eval provides an expression evaluator.
ch07ex14
Ch07ex14 implements a new type min that implements the Expr interface.
Ch07ex14 implements a new type min that implements the Expr interface.
ch07ex14/eval
Package eval provides an expression evaluator.
Package eval provides an expression evaluator.
ch07ex15
Ch07ex15 reads one expression from standard input, prompts for variable values and evaluates the expression in the resulting environment.
Ch07ex15 reads one expression from standard input, prompts for variable values and evaluates the expression in the resulting environment.
ch07ex16
Ch07ex16 implements an expression evaluator as a web service.
Ch07ex16 implements an expression evaluator as a web service.
ch07ex17
Ch07ex17 extends xmlselect to select elements not just by name, but by their attributes, too.
Ch07ex17 extends xmlselect to select elements not just by name, but by their attributes, too.
ch07ex18
Ch07ex18 reads an arbirtrary XML document and constructs a tree of generic nodes that represent it.
Ch07ex18 reads an arbirtrary XML document and constructs a tree of generic nodes that represent it.
chapter08
ch08ex01/clock
Clock is a TCP server that periodically writes the time.
Clock is a TCP server that periodically writes the time.
ch08ex01/clockwall
Clockwall is a client of multiple clock servers at once; it reads the time from each one and displays the results in a table.
Clockwall is a client of multiple clock servers at once; it reads the time from each one and displays the results in a table.
ch08ex02
Ch08ex02 is a minimal implementation of a concurrent FTP server.
Ch08ex02 is a minimal implementation of a concurrent FTP server.
ch08ex03
Ch08ex03 is a simple netcat that closes read and write halves of its TCP connection separately.
Ch08ex03 is a simple netcat that closes read and write halves of its TCP connection separately.
ch08ex03/reverb1
Reverb1 is a TCP server that simulates an echo.
Reverb1 is a TCP server that simulates an echo.
ch08ex04
Ch08ex04 is a TCP server that simulates an echo, using a sync.WaitGroup per connection to let echo goroutines finish cleanly.
Ch08ex04 is a TCP server that simulates an echo, using a sync.WaitGroup per connection to let echo goroutines finish cleanly.
ch08ex05
Ch08ex05 is a concurrent version of the Mandelbrot program from Chapter 3.3.
Ch08ex05 is a concurrent version of the Mandelbrot program from Chapter 3.3.
ch08ex06
Ch08ex06 is a concurrent crawler with depth-limiting.
Ch08ex06 is a concurrent crawler with depth-limiting.
ch08ex07
Ch08ex07 makes local copies of the pages it crawls concurrently, creating directories as necessary, except for pages from different domains.
Ch08ex07 makes local copies of the pages it crawls concurrently, creating directories as necessary, except for pages from different domains.
ch08ex07/links
Package links provides functions to fetch pages via GET requests and extract links from them.
Package links provides functions to fetch pages via GET requests and extract links from them.
ch08ex08
Ch08ex08 is a reverb server that disconnects any client that doesn't shout anything for 10 seconds.
Ch08ex08 is a reverb server that disconnects any client that doesn't shout anything for 10 seconds.
ch08ex09
Ch08ex09 computes the disk usage of the files in directory trees.
Ch08ex09 computes the disk usage of the files in directory trees.
ch08ex10
Ch08ex10 is a concurrent web crawler that supports cancellation.
Ch08ex10 is a concurrent web crawler that supports cancellation.
ch08ex11
Ch08ex11 fetches multiple URLs in parallel and cancels all other requests when the first one has finished.
Ch08ex11 fetches multiple URLs in parallel and cancels all other requests when the first one has finished.
ch08ex12
Ch08ex12 is the chat program from Chapter 8.10, announcing the current clients to new arrivals.
Ch08ex12 is the chat program from Chapter 8.10, announcing the current clients to new arrivals.
ch08ex13
Ch08ex13 is the chat server from Chapter 8 Section 10: it disconnects idle clients (10 seconds timeout, adjustable with -timeout SECONDS flag).
Ch08ex13 is the chat server from Chapter 8 Section 10: it disconnects idle clients (10 seconds timeout, adjustable with -timeout SECONDS flag).
ch08ex14
Ch08ex14 is the chat server from Chaper 8 Section 10, using names for clients instead of IP addresses.
Ch08ex14 is the chat server from Chaper 8 Section 10, using names for clients instead of IP addresses.
ch08ex15
Ch08ex15 is the chat server from Chaper 8 Section 10, skipping clients if they aren't ready to receive a message.
Ch08ex15 is the chat server from Chaper 8 Section 10, skipping clients if they aren't ready to receive a message.
chapter09
ch09ex01
Package ch09ex01 adds a Withdraw function to the bank package described in Chapter 9, Section 1.
Package ch09ex01 adds a Withdraw function to the bank package described in Chapter 9, Section 1.
ch09ex02
Package ch09ex02 provides the PopCount function from Chapter 2 using lazy initialization.
Package ch09ex02 provides the PopCount function from Chapter 2 using lazy initialization.
ch09ex03
Package ch09ex03 provides a concurrency-safe memoization a function of a function.
Package ch09ex03 provides a concurrency-safe memoization a function of a function.
ch09ex04
Ch09ex04 takes an optional parameter to indicate the number of goroutines to create, then creates that number of channels and goroutines and finally measures how long a message takes to pass through all of them.
Ch09ex04 takes an optional parameter to indicate the number of goroutines to create, then creates that number of channels and goroutines and finally measures how long a message takes to pass through all of them.
ch09ex05
Ch09ex05 creates two goroutines passing messages back and forth on two channels.
Ch09ex05 creates two goroutines passing messages back and forth on two channels.
chapter10
ch10ex01
Ch10ex01 converts an image file read from standard input to the format specified with the -to flag (default: png) and writes it to standard output.
Ch10ex01 converts an image file read from standard input to the format specified with the -to flag (default: png) and writes it to standard output.
ch10ex02
Ch10ex02 prints the files and their sizes from archive files given as command line parameters.
Ch10ex02 prints the files and their sizes from archive files given as command line parameters.
ch10ex04
Ch10ex04 takes any number of packages as parameters (default: package of current directory) and prints all packages in the workspace that depend on it transitively.
Ch10ex04 takes any number of packages as parameters (default: package of current directory) and prints all packages in the workspace that depend on it transitively.
chapter11
ch11ex01
Package ch11ex01 provides the Charcount function from Section 4.3 as a library function to be tested.
Package ch11ex01 provides the Charcount function from Section 4.3 as a library function to be tested.
ch11ex02
Package intset provides a set of integers based on a bit vector.
Package intset provides a set of integers based on a bit vector.
ch11ex03
Package ch11ex03 provides utilities for word games.
Package ch11ex03 provides utilities for word games.
ch11ex04
Package ch11ex04 provides utilities for word games.
Package ch11ex04 provides utilities for word games.
ch11ex06
Package ch11ex06 provides a bitfield implementation.
Package ch11ex06 provides a bitfield implementation.
ch11ex07
Package ch11ex07 provides a set of integers based on a bit vector.
Package ch11ex07 provides a set of integers based on a bit vector.
chapter12
ch12ex01
Package ch12ex01 provides a means to display structured data.
Package ch12ex01 provides a means to display structured data.
ch12ex02
Package ch12ex02 provides a means to display structured data.
Package ch12ex02 provides a means to display structured data.
ch12ex03
Package ch12ex03 provides an S-expression encoder with the missing cases from the book implemented.
Package ch12ex03 provides an S-expression encoder with the missing cases from the book implemented.
ch12ex04
Package ch12ex04 provides a pretty-printing encoder for S-expressions.
Package ch12ex04 provides a pretty-printing encoder for S-expressions.
ch12ex05
Package ch12ex05 provides a JSON encoder.
Package ch12ex05 provides a JSON encoder.
ch12ex06
Package ch12ex06 provides an S-expression encoder which doesn't encode a field whose value is the zero value of its type.
Package ch12ex06 provides an S-expression encoder which doesn't encode a field whose value is the zero value of its type.
ch12ex07
Package ch12ex07 provides an S-expression encoder with a streaming API.
Package ch12ex07 provides an S-expression encoder with a streaming API.
ch12ex08
Package ch12ex08 provides an S-expression decoder using an io.Reader instead of a byte slice.
Package ch12ex08 provides an S-expression decoder using an io.Reader instead of a byte slice.
ch12ex09
Package ch12ex09 provides a token-based API to decode S-expressions.
Package ch12ex09 provides a token-based API to decode S-expressions.
ch12ex10
Package ch12ex10 provides an S-expression decoder extended to handle booleans, floats and interfaces.
Package ch12ex10 provides an S-expression decoder extended to handle booleans, floats and interfaces.
ch12ex11
Package ch12ex11 provides an encoder for URL query strings that takes struct tags for "http" into account.
Package ch12ex11 provides an encoder for URL query strings that takes struct tags for "http" into account.
ch12ex12
Package ch12ex12 provides a reflection-based parser for URL parameters with support for parameter validation.
Package ch12ex12 provides a reflection-based parser for URL parameters with support for parameter validation.
ch12ex13
Package ch12ex13 provides a means for converting Go objects to and from S-expressions.
Package ch12ex13 provides a means for converting Go objects to and from S-expressions.
chapter13
ch13ex01
Package ch13ex01 provides a deep equivalence relation that considers numbers of any type equal if they differ by less than one part in a billion.
Package ch13ex01 provides a deep equivalence relation that considers numbers of any type equal if they differ by less than one part in a billion.
ch13ex02
Package ch13ex02 provides a function that checks if its argument is cylic.
Package ch13ex02 provides a function that checks if its argument is cylic.
ch13ex03
Package ch13ex03 provides a writer that uses bzip2 compression (bzip.org), safe for concurrent use.
Package ch13ex03 provides a writer that uses bzip2 compression (bzip.org), safe for concurrent use.
ch13ex04
Package ch13ex04 provides a writer that uses bzip2 compression (bzip.org) by wrapping the /bin/bzip2 executable.
Package ch13ex04 provides a writer that uses bzip2 compression (bzip.org) by wrapping the /bin/bzip2 executable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL