gopl

module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2019 License: MIT

README

gopl

Build Status codecov Go Report Card

English | 简体中文

gopl(The Go Programming Language)是一个包含了 《Go 程序设计语言》 中全部示例代码和全部练习题参考答案的项目。

Go 程序设计语言

Go 程序设计语言

ISBN: 978-7111558422

安装

git clone https://github.com/linehk/gopl.git

参与贡献

如果你觉得我的参考答案有什么需要改进的地方,欢迎发起 Pull Request。

如果有重大变化,请先打开一个 Issue,讨论您想要改变的内容。

开源许可证

MIT License

祝语

Happy Go programming, I hope you enjoy writing Go as much as I do.

Directories

Path Synopsis
ch1
dup1 command
Dup1 prints the text of each line that appears more than once in the standard input, preceded by its count.
Dup1 prints the text of each line that appears more than once in the standard input, preceded by its count.
dup2 command
Dup2 prints the count and text of lines that appear more than once in the input.
Dup2 prints the count and text of lines that appear more than once in the input.
dup3 command
Dup3 prints the count and text of lines that appear more than once in the named input files.
Dup3 prints the count and text of lines that appear more than once in the named input files.
echo1 command
Echo1 prints its command-line arguments.
Echo1 prints its command-line arguments.
echo2 command
Echo2 prints its commamd-line arguments.
Echo2 prints its commamd-line arguments.
echo3 command
Echo3 prints its command-line arguments.
Echo3 prints its command-line arguments.
exercise1.1 command
exercise1.10 command
Fetchall fetches URLs in parallel and reports their times and sizes.
Fetchall fetches URLs in parallel and reports their times and sizes.
exercise1.11 command
越长的参数运行得越久,网站没回应的话会跳过。
越长的参数运行得越久,网站没回应的话会跳过。
exercise1.12 command
Lissajous generates GIF animations of random Lissajous figures.
Lissajous generates GIF animations of random Lissajous figures.
exercise1.2 command
exercise1.4 command
exercise1.5 command
Lissajous generates GIF animations of random Lissajous figures.
Lissajous generates GIF animations of random Lissajous figures.
exercise1.6 command
Lissajous generates GIF animations of random Lissajous figures.
Lissajous generates GIF animations of random Lissajous figures.
exercise1.7 command
Fetch prints the content found at each specified URL.
Fetch prints the content found at each specified URL.
exercise1.8 command
Fetch prints the content found at each specified URL.
Fetch prints the content found at each specified URL.
exercise1.9 command
Fetch prints the content found at each specified URL.
Fetch prints the content found at each specified URL.
fetch command
Fetch prints the content found at each specified URL.
Fetch prints the content found at each specified URL.
fetchall command
Fetchall fetches URLs in parallel and reports their times and sizes.
Fetchall fetches URLs in parallel and reports their times and sizes.
helloworld command
Helloworld is our first Go program.
Helloworld is our first Go program.
lissajous command
Lissajous generates GIF animations of random Lissajous figures.
Lissajous generates GIF animations of random Lissajous figures.
lissajous_web command
Lissajous generates GIF animations of random Lissajous figures.
Lissajous generates GIF animations of random Lissajous figures.
server1 command
Server1 is a minimal "echo" server.
Server1 is a minimal "echo" server.
server2 command
Server2 is a minimal "echo" and counter server.
Server2 is a minimal "echo" and counter server.
server3 command
Server3 is an "echo" server that displays request parameters.
Server3 is an "echo" server that displays request parameters.
ch10
cross command
The cross command prints the values of GOOS and GOARCH for this target.
The cross command prints the values of GOOS and GOARCH for this target.
exercise10.1 command
exercise10.4 command
jpeg command
The jpeg command reads a PNG image from the standard input and writes it as a JPEG image to the standard output.
The jpeg command reads a PNG image from the standard input and writes it as a JPEG image to the standard output.
ch11
echo command
Echo prints its command-line arguments.
Echo prints its command-line arguments.
exercise11.1
Charcount computes counts of Unicode characters.
Charcount computes counts of Unicode characters.
exercise11.2
Package intset provides a set of integers based on a bit vector.
Package intset provides a set of integers based on a bit vector.
exercise11.3
Package word provides utilities for word games.
Package word provides utilities for word games.
exercise11.4
Package word provides utilities for word games.
Package word provides utilities for word games.
exercise11.7
Package intset provides a set of integers based on a bit vector.
Package intset provides a set of integers based on a bit vector.
storage1
Package storage is part of a hypothetical cloud storage server.
Package storage is part of a hypothetical cloud storage server.
storage2
Package storage is part of a hypothetical cloud storage server.
Package storage is part of a hypothetical cloud storage server.
word1
Package word provides utilities for word games.
Package word provides utilities for word games.
word2
Package word provides utilities for word games.
Package word provides utilities for word games.
ch12
exercise12.12
Package params provides a reflection-based parser for URL parameters.
Package params provides a reflection-based parser for URL parameters.
exercise12.13
Package sexpr provides a means for converting Go objects to and from S-expressions.
Package sexpr provides a means for converting Go objects to and from S-expressions.
exercise12.8
Package sexpr provides a means for converting Go objects to and from S-expressions.
Package sexpr provides a means for converting Go objects to and from S-expressions.
format
Package format provides an Any function that can format any value.
Package format provides an Any function that can format any value.
methods
Package methods provides a function to print the methods of any value.
Package methods provides a function to print the methods of any value.
params
Package params provides a reflection-based parser for URL parameters.
Package params provides a reflection-based parser for URL parameters.
search command
Search is a demo of the params.Unpack function.
Search is a demo of the params.Unpack function.
sexpr
Package sexpr provides a means for converting Go objects to and from S-expressions.
Package sexpr provides a means for converting Go objects to and from S-expressions.
ch13
bzip
Package bzip provides a writer that uses bzip2 compression (bzip.org).
Package bzip provides a writer that uses bzip2 compression (bzip.org).
bzipper command
Bzipper reads input, bzip2-compresses it, and writes it out.
Bzipper reads input, bzip2-compresses it, and writes it out.
equal
Package equal provides a deep equivalence relation for arbitrary values.
Package equal provides a deep equivalence relation for arbitrary values.
exercise13.1
Package equal provides a deep equivalence relation for arbitrary values.
Package equal provides a deep equivalence relation for arbitrary values.
exercise13.3
Package bzip provides a writer that uses bzip2 compression (bzip.org).
Package bzip provides a writer that uses bzip2 compression (bzip.org).
unsafeptr command
Package main demonstrates basic use of unsafe.Pointer.
Package main demonstrates basic use of unsafe.Pointer.
ch2
boiling command
Boiling prints the boiling point of water.
Boiling prints the boiling point of water.
cf command
Cf converts its numeric argument to Celsius and Fahrenheit.
Cf converts its numeric argument to Celsius and Fahrenheit.
echo4 command
Echo4 prints its command-line arguments.
Echo4 prints its command-line arguments.
exercise2.1
Package tempconv performs Celsius and Fahrenheit conversion.
Package tempconv performs Celsius and Fahrenheit conversion.
exercise2.2 command
Package tempconv performs Celsius and Fahrenheit and Kelvin conversion.
Package tempconv performs Celsius and Fahrenheit and Kelvin conversion.
ftoc command
Ftoc prints two Fahrenheit-to-Celsius conversions.
Ftoc prints two Fahrenheit-to-Celsius conversions.
tempconv
Package tempconv performs Celsius and Fahrenheit conversion.
Package tempconv performs Celsius and Fahrenheit conversion.
tempconv0
Package tempconv performs Celsius and Fahrenheit temperature computations.
Package tempconv performs Celsius and Fahrenheit temperature computations.
ch3
basename1 command
Basename1 reads file names from stdin and prints the base name of each one.
Basename1 reads file names from stdin and prints the base name of each one.
basename2 command
Basename2 reads file names from stdin and prints the base name of each one.
Basename2 reads file names from stdin and prints the base name of each one.
comma command
Comma prints its argument numbers with a comma at each power of 1000.
Comma prints its argument numbers with a comma at each power of 1000.
exercise3.1 command
Surface computes an SVG rendering of a 3-D surface function.
Surface computes an SVG rendering of a 3-D surface function.
exercise3.10 command
exercise3.11 command
exercise3.12 command
exercise3.13 command
exercise3.2 command
Surface computes an SVG rendering of a 3-D surface function.
Surface computes an SVG rendering of a 3-D surface function.
exercise3.3 command
Surface computes an SVG rendering of a 3-D surface function.
Surface computes an SVG rendering of a 3-D surface function.
exercise3.4 command
Surface computes an SVG rendering of a 3-D surface function.
Surface computes an SVG rendering of a 3-D surface function.
exercise3.5 command
Mandelbrot emits a PNG image of the Mandelbrot fractal.
Mandelbrot emits a PNG image of the Mandelbrot fractal.
exercise3.6 command
Mandelbrot emits a PNG image of the Mandelbrot fractal.
Mandelbrot emits a PNG image of the Mandelbrot fractal.
exercise3.7 command
Mandelbrot emits a PNG image of the Mandelbrot fractal.
Mandelbrot emits a PNG image of the Mandelbrot fractal.
exercise3.9 command
mandelbrot command
Mandelbrot emits a PNG image of the Mandelbrot fractal.
Mandelbrot emits a PNG image of the Mandelbrot fractal.
netflag command
Netflag demonstrates an integer type used as a bit field.
Netflag demonstrates an integer type used as a bit field.
printints command
Printints demonstrates the use of bytes.Buffer to format a sring.
Printints demonstrates the use of bytes.Buffer to format a sring.
surface command
Surface computes an SVG rendering of a 3-D surface function.
Surface computes an SVG rendering of a 3-D surface function.
ch4
append command
Append illustrates the behavior of the built-in append function.
Append illustrates the behavior of the built-in append function.
autoescape command
Autoescape demonstrates automatic HTML escaping in html/template.
Autoescape demonstrates automatic HTML escaping in html/template.
charcount command
Charcount computes counts of Unicode characters.
Charcount computes counts of Unicode characters.
dedup command
Dedup prints only one instance of each line; duplicates are removed.
Dedup prints only one instance of each line; duplicates are removed.
embed command
Embed demonstrates basic struct embedding.
Embed demonstrates basic struct embedding.
exercise4.1 command
exercise4.10 command
exercise4.11 command
exercise4.12 command
exercise4.13 command
exercise4.14 command
exercise4.2 command
exercise4.3 command
exercise4.4 command
exercise4.5 command
exercise4.6 command
exercise4.7 command
exercise4.8 command
exercise4.9 command
graph command
Graph shows how to use a map of maps to represent a directed graph.
Graph shows how to use a map of maps to represent a directed graph.
issues command
Issues prints a table of GitHub issues matching the search terms.
Issues prints a table of GitHub issues matching the search terms.
issueshtml command
Issueshtml prints an HTML table of issues matching the search terms.
Issueshtml prints an HTML table of issues matching the search terms.
issuesreport command
Issuesreport prints a report of issues matching the search terms.
Issuesreport prints a report of issues matching the search terms.
movie command
Movie prints Movies as JSON.
Movie prints Movies as JSON.
nonempty command
Nonempty is an example of an in-place slice algorithm.
Nonempty is an example of an in-place slice algorithm.
rev command
Rev reverses a slice.
Rev reverses a slice.
sha256 command
The sha256 command computes the SHA256 hash (an array) of a string.
The sha256 command computes the SHA256 hash (an array) of a string.
treesort
Package treesort provides insertion sort using an unbalanced binary tree.
Package treesort provides insertion sort using an unbalanced binary tree.
ch5
defer1 command
Defer1 demonstrates a deferred call being invoked during a panic.
Defer1 demonstrates a deferred call being invoked during a panic.
defer2 command
Defer2 demonstrates a deferred call to runtime.Stack during a panic.
Defer2 demonstrates a deferred call to runtime.Stack during a panic.
exercise5.1 command
exercise5.10 command
exercise5.11 command
exercise5.12 command
exercise5.13 command
exercise5.14 command
exercise5.15 command
exercise5.16 command
exercise5.17 command
exercise5.18 command
exercise5.19 command
exercise5.2 command
exercise5.3 command
exercise5.4 command
exercise5.5 command
exercise5.6 command
Surface computes an SVG rendering of a 3-D surface function.
Surface computes an SVG rendering of a 3-D surface function.
exercise5.7 command
exercise5.8 command
exercise5.9 command
fetch command
Fetch saves the contents of a URL into a local file.
Fetch saves the contents of a URL into a local file.
findlinks1 command
Findlinks1 prints the links in an HTML document read from standard inpit.
Findlinks1 prints the links in an HTML document read from standard inpit.
findlinks2 command
Findlinks2 does an HTTP GET on each URL, parses the result as HTML, and prints the links within it.
Findlinks2 does an HTTP GET on each URL, parses the result as HTML, and prints the links within it.
findlinks3 command
links
Package links provides a link-extraction function.
Package links provides a link-extraction function.
outline command
Outline prints the outline of an HTML document tree.
Outline prints the outline of an HTML document tree.
outline2 command
Outline prints the outline of an HTML document tree.
Outline prints the outline of an HTML document tree.
squars command
The squares program demonstrates a function value with state.
The squares program demonstrates a function value with state.
sum command
The sum program demonstrates a variadic function.
The sum program demonstrates a variadic function.
title1 command
Title1 prints the title of an HTML document specified by a URL.
Title1 prints the title of an HTML document specified by a URL.
title2 command
Title2 prints the title of an HTML document specified by a URL.
Title2 prints the title of an HTML document specified by a URL.
topsort command
The topsort program prints the nodes of a DAG in topological order.
The topsort program prints the nodes of a DAG in topological order.
trace command
The trace program uses defer to add entry/exit diagnostics to a function.
The trace program uses defer to add entry/exit diagnostics to a function.
wait command
The wait program waits for an HTTP server to start responding.
The wait program waits for an HTTP server to start responding.
ch6
coloredpoint command
Coloredpoint demonstrates struct embeding.
Coloredpoint demonstrates struct embeding.
exercise6.1
Package intset provides a set of integers based on a bit vector.
Package intset provides a set of integers based on a bit vector.
exercise6.2
Package intset provides a set of integers based on a bit vector.
Package intset provides a set of integers based on a bit vector.
exercise6.3
Package intset provides a set of integers based on a bit vector.
Package intset provides a set of integers based on a bit vector.
exercise6.4
Package intset provides a set of integers based on a bit vector.
Package intset provides a set of integers based on a bit vector.
exercise6.5
Package intset provides a set of integers based on a bit vector.
Package intset provides a set of integers based on a bit vector.
geometry
Package geometry defines simply types for plane geometry.
Package geometry defines simply types for plane geometry.
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.
urlvalues command
The urlvalues command demonstrates a map type with methods.
The urlvalues command demonstrates a map type with methods.
ch7
bytecounter command
Bytecounter demonstrates an implementation of io.Writer that counts bytes.
Bytecounter demonstrates an implementation of io.Writer that counts bytes.
eval
Package eval provides an expression evaluator.
Package eval provides an expression evaluator.
exercise7.1 command
exercise7.10 command
exercise7.11 command
exercise7.12 command
exercise7.13
Package eval provides an expression evaluator.
Package eval provides an expression evaluator.
exercise7.14
Package eval provides an expression evaluator.
Package eval provides an expression evaluator.
exercise7.15 command
exercise7.15/eval
Package eval provides an expression evaluator.
Package eval provides an expression evaluator.
exercise7.16 command
exercise7.16/eval
Package eval provides an expression evaluator.
Package eval provides an expression evaluator.
exercise7.17 command
exercise7.18 command
exercise7.2 command
exercise7.3
Package treesort provides insertion sort using an unbalanced binary tree.
Package treesort provides insertion sort using an unbalanced binary tree.
exercise7.4 command
exercise7.5 command
exercise7.6 command
exercise7.7
因为 temp 的类型是 *Celsius,而 *Celsius 实现了 String() 方法 所以在调用 fmt.Println(*temp) 会调用 String() 方法
因为 temp 的类型是 *Celsius,而 *Celsius 实现了 String() 方法 所以在调用 fmt.Println(*temp) 会调用 String() 方法
exercise7.8 command
exercise7.9 command
http1 command
Http1 is a rudimentary e-commerce server.
Http1 is a rudimentary e-commerce server.
http2 command
Http2 is an e-commerce server with /list and /price endpoints.
Http2 is an e-commerce server with /list and /price endpoints.
http3 command
Http3 is an e-commerce server that registers the /list and /price endpoints by calling (*http.ServeMux).Handle.
Http3 is an e-commerce server that registers the /list and /price endpoints by calling (*http.ServeMux).Handle.
http3a command
Http3a is an e-commerce server that registers the /list and /price endpoints by calling (*http.ServeMux).HandleFunc.
Http3a is an e-commerce server that registers the /list and /price endpoints by calling (*http.ServeMux).HandleFunc.
http4 command
Http4 is an e-commerce server that registers the /list and /price endpoint by calling http.HandleFunc.
Http4 is an e-commerce server that registers the /list and /price endpoint by calling http.HandleFunc.
sleep command
The sleep program sleeps for a specified period of time.
The sleep program sleeps for a specified period of time.
sorting command
Sorting sorts a music playlist into a variety of orders.
Sorting sorts a music playlist into a variety of orders.
surface command
The surface program plots the 3-D surface of a user-provided function.
The surface program plots the 3-D surface of a user-provided function.
tempconv
Package tempconv performs Celsius and Fahrenheit temperature computations.
Package tempconv performs Celsius and Fahrenheit temperature computations.
tempflag command
Tempflag prints the value of its -temp (temperature) flag.
Tempflag prints the value of its -temp (temperature) flag.
xmlselect command
Xmlselect prints the text of selected elements of an XML document.
Xmlselect prints the text of selected elements of an XML document.
ch8
cake
Package cake provides a simulation of a concurrent cake shop with numerous parameters.
Package cake provides a simulation of a concurrent cake shop with numerous parameters.
chat command
Chat is a server that lets clients chat with each other.
Chat is a server that lets clients chat with each other.
clock1 command
Clock1 is a TCP server that periodically writes the time.
Clock1 is a TCP server that periodically writes the time.
clock2 command
Clock is a TCP server that periodically writes the time.
Clock is a TCP server that periodically writes the time.
countdown1 command
Countdown implements the countdown for a rocket launch.
Countdown implements the countdown for a rocket launch.
countdown2 command
Countdown implements the countdown for a rocket launch.
Countdown implements the countdown for a rocket launch.
countdown3 command
Countdown implements the countdown for a rocket launch.
Countdown implements the countdown for a rocket launch.
crawl1 command
Crawl1 crawls web links starting with the command-line arguments.
Crawl1 crawls web links starting with the command-line arguments.
crawl2 command
Crawl2 crawls web links starting with the command-line arguments.
Crawl2 crawls web links starting with the command-line arguments.
crawl3 command
Crawl3 crawls web links starting with the command-line arguments.
Crawl3 crawls web links starting with the command-line arguments.
du1 command
The du1 command computes the disk usage of the files in a directory.
The du1 command computes the disk usage of the files in a directory.
du2 command
The du2 command computes the disk usage of the files in a directory.
The du2 command computes the disk usage of the files in a directory.
du3 command
The du3 command computes the disk usage of the files in a directory.
The du3 command computes the disk usage of the files in a directory.
du4 command
The du4 command computes the disk usage of the files in a directory.
The du4 command computes the disk usage of the files in a directory.
exercise8.10 command
exercise8.10/links
Package links provides a link-extraction function.
Package links provides a link-extraction function.
exercise8.11 command
exercise8.12 command
exercise8.13 command
Chat is a server that lets clients chat with each other.
Chat is a server that lets clients chat with each other.
exercise8.14 command
exercise8.15 command
exercise8.3 command
Netcat is a simple read/write client for TCP servers.
Netcat is a simple read/write client for TCP servers.
exercise8.4 command
exercise8.5 command
exercise8.5/mandelbrot
Mandelbrot emits a PNG image of the Mandelbrot fractal.
Mandelbrot emits a PNG image of the Mandelbrot fractal.
exercise8.6 command
exercise8.7 command
exercise8.8 command
exercise8.9 command
netcat1 command
Netcat1 is a read-only TCP client.
Netcat1 is a read-only TCP client.
netcat2 command
Netcat is a simple read/write client for TCP servers.
Netcat is a simple read/write client for TCP servers.
netcat3 command
Netcat is a simple read/write client for TCP servers.
Netcat is a simple read/write client for TCP servers.
pipeline1 command
Pipeline1 demonstrates an infinite 3-stage pipeline.
Pipeline1 demonstrates an infinite 3-stage pipeline.
pipeline2 command
Pipeline2 demonstrates a finite 3-stage pipeline.
Pipeline2 demonstrates a finite 3-stage pipeline.
pipeline3 command
Pipeline3 demonstrates a finite 3-stage pipeline with range, close, and unidirectional channel types.
Pipeline3 demonstrates a finite 3-stage pipeline with range, close, and unidirectional channel types.
reverb1 command
Rever1 is a TCP server that simulates an echo.
Rever1 is a TCP server that simulates an echo.
reverb2 command
Rever2 is a TCP server that simulates an echo.
Rever2 is a TCP server that simulates an echo.
spinner command
Spinner displays an animation while computing the 45th Fibonacci number.
Spinner displays an animation while computing the 45th Fibonacci number.
thumbnail command
The thumbnail command produces thumbnails of JPEG files whose names are provided on each line of the standard input.
The thumbnail command produces thumbnails of JPEG files whose names are provided on each line of the standard input.
thumbnail/thumbnail
The thumbnail package produces thumbnail-size images from larger images.
The thumbnail package produces thumbnail-size images from larger images.
ch9
bank1
Package bank provides a concurrency-safe bank with one account.
Package bank provides a concurrency-safe bank with one account.
bank2
Package bank provides a concurrency-safe bank with one account.
Package bank provides a concurrency-safe bank with one account.
bank3
Package bank provides a concurrency-safe single-account bank.
Package bank provides a concurrency-safe single-account bank.
exercise9.3/memotest
Package memotest provides common functions for testing various designs of the memo package.
Package memotest provides common functions for testing various designs of the memo package.
exercise9.6 command
exercise9.6/mandelbrot
Mandelbrot emits a PNG image of the Mandelbrot fractal.
Mandelbrot emits a PNG image of the Mandelbrot fractal.
memo1
Package memo provides a concurrency-unsafe memoization of a function of type Func.
Package memo provides a concurrency-unsafe memoization of a function of type Func.
memo2
Package memo provides a concurrency-safe memoization a function of type Func.
Package memo provides a concurrency-safe memoization a function of type Func.
memo3
Package memo provides a concurrency-safe memoization a function of type Func.
Package memo provides a concurrency-safe memoization a function of type Func.
memo4
Package memo provides a concurrency-safe memoization a function of a function.
Package memo provides a concurrency-safe memoization a function of a function.
memo5
Package memo provides a concurrency-safe non-blocking memoization of a function.
Package memo provides a concurrency-safe non-blocking memoization of a function.
memotest
Package memotest provides common functions for testing various designs of the memo package.
Package memotest provides common functions for testing various designs of the memo package.

Jump to

Keyboard shortcuts

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