mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 05:33:04 +08:00
修改标点错误 (#494)
This commit is contained in:
@@ -117,8 +117,8 @@ func MakeAddSuffix(suffix string) func(string) string {
|
|||||||
现在,我们可以生成如下函数:
|
现在,我们可以生成如下函数:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
addBmp := MakeAddSuffix(“.bmp”)
|
addBmp := MakeAddSuffix(".bmp")
|
||||||
addJpeg := MakeAddSuffix(“.jpeg”)
|
addJpeg := MakeAddSuffix(".jpeg")
|
||||||
```
|
```
|
||||||
|
|
||||||
然后调用它们:
|
然后调用它们:
|
||||||
|
@@ -65,7 +65,7 @@ func main() {
|
|||||||
下面的代码试图访问一个未引用的变量或者函数,甚至没有编译。将会返回一个错误:
|
下面的代码试图访问一个未引用的变量或者函数,甚至没有编译。将会返回一个错误:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
fmt.Printf(“Float from package1: %f\n”, pack1.pack1Float)
|
fmt.Printf("Float from package1: %f\n", pack1.pack1Float)
|
||||||
```
|
```
|
||||||
|
|
||||||
错误:
|
错误:
|
||||||
|
@@ -22,7 +22,7 @@ Go 是怎么处理普通错误的呢?通过在函数和方法中返回错误
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
if value, err := pack1.Func1(param1); err != nil {
|
if value, err := pack1.Func1(param1); err != nil {
|
||||||
fmt.Printf(“Error %s in pack1.Func1 with parameter %v”, err.Error(), param1)
|
fmt.Printf("Error %s in pack1.Func1 with parameter %v", err.Error(), param1)
|
||||||
return // or: return err
|
return // or: return err
|
||||||
} else {
|
} else {
|
||||||
// Process(value)
|
// Process(value)
|
||||||
|
@@ -35,7 +35,7 @@ func errorHandler(fn fType1) fType1 {
|
|||||||
return func(a type1, b type2) {
|
return func(a type1, b type2) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err, ok := recover().(error); ok {
|
if err, ok := recover().(error); ok {
|
||||||
log.Printf(“run time panic: %v”, err)
|
log.Printf("run time panic: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
fn(a, b)
|
fn(a, b)
|
||||||
|
@@ -101,7 +101,7 @@ include $(GOROOT)/src/Make.pkg
|
|||||||
```go
|
```go
|
||||||
func TestEven(t *testing.T) {
|
func TestEven(t *testing.T) {
|
||||||
if Even(10) {
|
if Even(10) {
|
||||||
t.Log(“Everything OK: 10 is even, just a test to see failed output!”)
|
t.Log("Everything OK: 10 is even, just a test to see failed output!")
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,9 +12,9 @@ var tests = []struct{ // Test table
|
|||||||
out string
|
out string
|
||||||
|
|
||||||
}{
|
}{
|
||||||
{“in1”, “exp1”},
|
{"in1", "exp1"},
|
||||||
{“in2”, “exp2”},
|
{"in2", "exp2"},
|
||||||
{“in3”, “exp3”},
|
{"in3", "exp3"},
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ func TestFunction(t *testing.T) {
|
|||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
s := FuncToBeTested(tt.in)
|
s := FuncToBeTested(tt.in)
|
||||||
if s != tt.out {
|
if s != tt.out {
|
||||||
t.Errorf(“%d. %q => %q, wanted: %q”, i, tt.in, s, tt.out)
|
t.Errorf("%d. %q => %q, wanted: %q", i, tt.in, s, tt.out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user