From f27a8d84bf7161c772f1cbe88b08adf2127e1356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=80=80?= Date: Fri, 2 Sep 2016 10:14:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B013.9=20(#280)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update 07.3.md * Update 07.3.md * Update 07.6.md * fix few problems * Update 10.6 and 10.8 * Update 11.6 and 11.7 * fix some problems before Chap13 * add a dot * Update 13.9 --- eBook/13.1.md | 18 +++++++++--------- eBook/13.4.md | 2 +- eBook/13.9.md | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/eBook/13.1.md b/eBook/13.1.md index c5967e6..7e516da 100644 --- a/eBook/13.1.md +++ b/eBook/13.1.md @@ -44,7 +44,7 @@ func main() { ```go func Sqrt(f float64) (float64, error) { if f < 0 { - return 0, errors.New (“math - square root of negative number”) + return 0, errors.New ("math - square root of negative number") } // implementation of Sqrt } @@ -54,7 +54,7 @@ func Sqrt(f float64) (float64, error) { ```go if f, err := Sqrt(-1); err != nil { - fmt.Printf(“Error: %s\n”, err) + fmt.Printf("Error: %s\n", err) } ``` @@ -65,13 +65,13 @@ if f, err := Sqrt(-1); err != nil { ```go // PathError records an error and the operation and file path that caused it. type PathError struct { - Op string // “open”, “unlink”, etc. + Op string // "open", "unlink", etc. Path string // The associated file. Err error // Returned by the system call. } func (e *PathError) String() string { - return e.Op + “ ” + e.Path + “: “+ e.Err.Error() + return e.Op + " " + e.Path + ": "+ e.Err.Error() } ``` @@ -94,7 +94,7 @@ switch err := err.(type) { PrintPathError(err) ... default: - fmt.Printf(“Not a special error, just %s\n”, err) + fmt.Printf("Not a special error, just %s\n", err) } ``` @@ -115,7 +115,7 @@ func (e *SyntaxError) String() string { return e.msg } ```go if serr, ok := err.(*json.SyntaxError); ok { line, col := findLine(f, serr.Offset) - return fmt.Errorf(“%s:%d:%d: %v”, f.Name(), line, col, err) + return fmt.Errorf("%s:%d:%d: %v", f.Name(), line, col, err) } ``` @@ -165,15 +165,15 @@ var ( ```go if f < 0 { - return 0, fmt.Errorf(“math: square root of negative number %g”, f) + return 0, fmt.Errorf("math: square root of negative number %g", f) } ``` 第二个例子:从命令行读取输入时,如果加了 help 标志,我们可以用有用的信息产生一个错误: ```go -if len(os.Args) > 1 && (os.Args[1] == “-h” || os.Args[1] == “--help”) { - err = fmt.Errorf(“usage: %s infile.txt outfile.txt”, filepath.Base(os.Args[0])) +if len(os.Args) > 1 && (os.Args[1] == "-h" || os.Args[1] == "--help") { + err = fmt.Errorf("usage: %s infile.txt outfile.txt", filepath.Base(os.Args[0])) return } ``` diff --git a/eBook/13.4.md b/eBook/13.4.md index b72d06f..ef10a03 100644 --- a/eBook/13.4.md +++ b/eBook/13.4.md @@ -10,7 +10,7 @@ 这在下面的代码中被很好地阐述了。我们有一个简单的 parse 包(示例 13.4)用来把输入的字符串解析为整数切片;这个包有自己特殊的 `ParseError`。 -当没有东西需要转换或者转换成整数失败时,这个包会 panic(在函数 fields2numbers 中)。但是可导出的 Parse 函数会从 panic 中 recover 并用所有这些信息返回一个错误给调用者。为了演示这个过程,在 panic_recover.go 中 调用了 parse 包(示例 13.4);不可解析的字符串会导致错误并被打印出来。 +当没有东西需要转换或者转换成整数失败时,这个包会 panic(在函数 fields2numbers 中)。但是可导出的 Parse 函数会从 panic 中 recover 并用所有这些信息返回一个错误给调用者。为了演示这个过程,在 [panic_recover.go](examples/chapter_13/parse/panic_recover.go) 中 调用了 parse 包(示例 13.4);不可解析的字符串会导致错误并被打印出来。 示例 13.4 [parse.go](examples/chapter_13/parse/parse.go): diff --git a/eBook/13.9.md b/eBook/13.9.md index 240eed7..82d6229 100644 --- a/eBook/13.9.md +++ b/eBook/13.9.md @@ -32,7 +32,7 @@ func TestFunction(t *testing.T) { ```go func verify(t *testing.T, testnum int, testcase, input, output, expected string) { - if input != output { + if expected != output { t.Errorf(“%d. %s with input = %s: output %s != %s”, testnum, testcase, input, output, expected) } }