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
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
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
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
Echo1 prints its command-line arguments.
Echo1 prints its command-line arguments.
echo2
Echo2 prints its commamd-line arguments.
Echo2 prints its commamd-line arguments.
echo3
Echo3 prints its command-line arguments.
Echo3 prints its command-line arguments.
exercise1.10
Fetchall fetches URLs in parallel and reports their times and sizes.
Fetchall fetches URLs in parallel and reports their times and sizes.
exercise1.11
越长的参数运行得越久,网站没回应的话会跳过。
越长的参数运行得越久,网站没回应的话会跳过。
exercise1.12
Lissajous generates GIF animations of random Lissajous figures.
Lissajous generates GIF animations of random Lissajous figures.
exercise1.5
Lissajous generates GIF animations of random Lissajous figures.
Lissajous generates GIF animations of random Lissajous figures.
exercise1.6
Lissajous generates GIF animations of random Lissajous figures.
Lissajous generates GIF animations of random Lissajous figures.
exercise1.7
Fetch prints the content found at each specified URL.
Fetch prints the content found at each specified URL.
exercise1.8
Fetch prints the content found at each specified URL.
Fetch prints the content found at each specified URL.
exercise1.9
Fetch prints the content found at each specified URL.
Fetch prints the content found at each specified URL.
fetch
Fetch prints the content found at each specified URL.
Fetch prints the content found at each specified URL.
fetchall
Fetchall fetches URLs in parallel and reports their times and sizes.
Fetchall fetches URLs in parallel and reports their times and sizes.
helloworld
Helloworld is our first Go program.
Helloworld is our first Go program.
lissajous
Lissajous generates GIF animations of random Lissajous figures.
Lissajous generates GIF animations of random Lissajous figures.
lissajous_web
Lissajous generates GIF animations of random Lissajous figures.
Lissajous generates GIF animations of random Lissajous figures.
server1
Server1 is a minimal "echo" server.
Server1 is a minimal "echo" server.
server2
Server2 is a minimal "echo" and counter server.
Server2 is a minimal "echo" and counter server.
server3
Server3 is an "echo" server that displays request parameters.
Server3 is an "echo" server that displays request parameters.
ch10
cross
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.
jpeg
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
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
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
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
Package main demonstrates basic use of unsafe.Pointer.
Package main demonstrates basic use of unsafe.Pointer.
ch2
boiling
Boiling prints the boiling point of water.
Boiling prints the boiling point of water.
cf
Cf converts its numeric argument to Celsius and Fahrenheit.
Cf converts its numeric argument to Celsius and Fahrenheit.
echo4
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
Package tempconv performs Celsius and Fahrenheit and Kelvin conversion.
Package tempconv performs Celsius and Fahrenheit and Kelvin conversion.
ftoc
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
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
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
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
Surface computes an SVG rendering of a 3-D surface function.
Surface computes an SVG rendering of a 3-D surface function.
exercise3.2
Surface computes an SVG rendering of a 3-D surface function.
Surface computes an SVG rendering of a 3-D surface function.
exercise3.3
Surface computes an SVG rendering of a 3-D surface function.
Surface computes an SVG rendering of a 3-D surface function.
exercise3.4
Surface computes an SVG rendering of a 3-D surface function.
Surface computes an SVG rendering of a 3-D surface function.
exercise3.5
Mandelbrot emits a PNG image of the Mandelbrot fractal.
Mandelbrot emits a PNG image of the Mandelbrot fractal.
exercise3.6
Mandelbrot emits a PNG image of the Mandelbrot fractal.
Mandelbrot emits a PNG image of the Mandelbrot fractal.
exercise3.7
Mandelbrot emits a PNG image of the Mandelbrot fractal.
Mandelbrot emits a PNG image of the Mandelbrot fractal.
mandelbrot
Mandelbrot emits a PNG image of the Mandelbrot fractal.
Mandelbrot emits a PNG image of the Mandelbrot fractal.
netflag
Netflag demonstrates an integer type used as a bit field.
Netflag demonstrates an integer type used as a bit field.
printints
Printints demonstrates the use of bytes.Buffer to format a sring.
Printints demonstrates the use of bytes.Buffer to format a sring.
surface
Surface computes an SVG rendering of a 3-D surface function.
Surface computes an SVG rendering of a 3-D surface function.
ch4
append
Append illustrates the behavior of the built-in append function.
Append illustrates the behavior of the built-in append function.
autoescape
Autoescape demonstrates automatic HTML escaping in html/template.
Autoescape demonstrates automatic HTML escaping in html/template.
charcount
Charcount computes counts of Unicode characters.
Charcount computes counts of Unicode characters.
dedup
Dedup prints only one instance of each line; duplicates are removed.
Dedup prints only one instance of each line; duplicates are removed.
embed
Embed demonstrates basic struct embedding.
Embed demonstrates basic struct embedding.
graph
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
Issues prints a table of GitHub issues matching the search terms.
Issues prints a table of GitHub issues matching the search terms.
issueshtml
Issueshtml prints an HTML table of issues matching the search terms.
Issueshtml prints an HTML table of issues matching the search terms.
issuesreport
Issuesreport prints a report of issues matching the search terms.
Issuesreport prints a report of issues matching the search terms.
movie
Movie prints Movies as JSON.
Movie prints Movies as JSON.
nonempty
Nonempty is an example of an in-place slice algorithm.
Nonempty is an example of an in-place slice algorithm.
rev
Rev reverses a slice.
Rev reverses a slice.
sha256
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
Defer1 demonstrates a deferred call being invoked during a panic.
Defer1 demonstrates a deferred call being invoked during a panic.
defer2
Defer2 demonstrates a deferred call to runtime.Stack during a panic.
Defer2 demonstrates a deferred call to runtime.Stack during a panic.
exercise5.6
Surface computes an SVG rendering of a 3-D surface function.
Surface computes an SVG rendering of a 3-D surface function.
fetch
Fetch saves the contents of a URL into a local file.
Fetch saves the contents of a URL into a local file.
findlinks1
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
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.
links
Package links provides a link-extraction function.
Package links provides a link-extraction function.
outline
Outline prints the outline of an HTML document tree.
Outline prints the outline of an HTML document tree.
outline2
Outline prints the outline of an HTML document tree.
Outline prints the outline of an HTML document tree.
squars
The squares program demonstrates a function value with state.
The squares program demonstrates a function value with state.
sum
The sum program demonstrates a variadic function.
The sum program demonstrates a variadic function.
title1
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
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
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
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
The wait program waits for an HTTP server to start responding.
The wait program waits for an HTTP server to start responding.
ch6
coloredpoint
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
The urlvalues command demonstrates a map type with methods.
The urlvalues command demonstrates a map type with methods.
ch7
bytecounter
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.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/eval
Package eval provides an expression evaluator.
Package eval provides an expression evaluator.
exercise7.16/eval
Package eval provides an expression evaluator.
Package eval provides an expression evaluator.
exercise7.3
Package treesort provides insertion sort using an unbalanced binary tree.
Package treesort provides insertion sort using an unbalanced binary tree.
exercise7.7
因为 temp 的类型是 *Celsius,而 *Celsius 实现了 String() 方法 所以在调用 fmt.Println(*temp) 会调用 String() 方法
因为 temp 的类型是 *Celsius,而 *Celsius 实现了 String() 方法 所以在调用 fmt.Println(*temp) 会调用 String() 方法
http1
Http1 is a rudimentary e-commerce server.
Http1 is a rudimentary e-commerce server.
http2
Http2 is an e-commerce server with /list and /price endpoints.
Http2 is an e-commerce server with /list and /price endpoints.
http3
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
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
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
The sleep program sleeps for a specified period of time.
The sleep program sleeps for a specified period of time.
sorting
Sorting sorts a music playlist into a variety of orders.
Sorting sorts a music playlist into a variety of orders.
surface
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
Tempflag prints the value of its -temp (temperature) flag.
Tempflag prints the value of its -temp (temperature) flag.
xmlselect
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
Chat is a server that lets clients chat with each other.
Chat is a server that lets clients chat with each other.
clock1
Clock1 is a TCP server that periodically writes the time.
Clock1 is a TCP server that periodically writes the time.
clock2
Clock is a TCP server that periodically writes the time.
Clock is a TCP server that periodically writes the time.
countdown1
Countdown implements the countdown for a rocket launch.
Countdown implements the countdown for a rocket launch.
countdown2
Countdown implements the countdown for a rocket launch.
Countdown implements the countdown for a rocket launch.
countdown3
Countdown implements the countdown for a rocket launch.
Countdown implements the countdown for a rocket launch.
crawl1
Crawl1 crawls web links starting with the command-line arguments.
Crawl1 crawls web links starting with the command-line arguments.
crawl2
Crawl2 crawls web links starting with the command-line arguments.
Crawl2 crawls web links starting with the command-line arguments.
crawl3
Crawl3 crawls web links starting with the command-line arguments.
Crawl3 crawls web links starting with the command-line arguments.
du1
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
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
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
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/links
Package links provides a link-extraction function.
Package links provides a link-extraction function.
exercise8.13
Chat is a server that lets clients chat with each other.
Chat is a server that lets clients chat with each other.
exercise8.3
Netcat is a simple read/write client for TCP servers.
Netcat is a simple read/write client for TCP servers.
exercise8.5/mandelbrot
Mandelbrot emits a PNG image of the Mandelbrot fractal.
Mandelbrot emits a PNG image of the Mandelbrot fractal.
netcat1
Netcat1 is a read-only TCP client.
Netcat1 is a read-only TCP client.
netcat2
Netcat is a simple read/write client for TCP servers.
Netcat is a simple read/write client for TCP servers.
netcat3
Netcat is a simple read/write client for TCP servers.
Netcat is a simple read/write client for TCP servers.
pipeline1
Pipeline1 demonstrates an infinite 3-stage pipeline.
Pipeline1 demonstrates an infinite 3-stage pipeline.
pipeline2
Pipeline2 demonstrates a finite 3-stage pipeline.
Pipeline2 demonstrates a finite 3-stage pipeline.
pipeline3
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
Rever1 is a TCP server that simulates an echo.
Rever1 is a TCP server that simulates an echo.
reverb2
Rever2 is a TCP server that simulates an echo.
Rever2 is a TCP server that simulates an echo.
spinner
Spinner displays an animation while computing the 45th Fibonacci number.
Spinner displays an animation while computing the 45th Fibonacci number.
thumbnail
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/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