ch7: fix code format

This commit is contained in:
chai2010
2016-01-21 10:22:10 +08:00
parent 2420954025
commit 0b5ec941ed
13 changed files with 208 additions and 186 deletions

View File

@@ -8,22 +8,22 @@
const debug = true
func main() {
var buf *bytes.Buffer
if debug {
buf = new(bytes.Buffer) // enable collection of output
}
f(buf) // NOTE: subtly incorrect!
if debug {
// ...use buf...
}
var buf *bytes.Buffer
if debug {
buf = new(bytes.Buffer) // enable collection of output
}
f(buf) // NOTE: subtly incorrect!
if debug {
// ...use buf...
}
}
// If out is non-nil, output will be written to it.
func f(out io.Writer) {
// ...do something...
if out != nil {
out.Write([]byte("done!\n"))
}
// ...do something...
if out != nil {
out.Write([]byte("done!\n"))
}
}
```
@@ -31,7 +31,7 @@ func f(out io.Writer) {
```go
if out != nil {
out.Write([]byte("done!\n")) // panic: nil pointer dereference
out.Write([]byte("done!\n")) // panic: nil pointer dereference
}
```
@@ -46,7 +46,7 @@ if out != nil {
```go
var buf io.Writer
if debug {
buf = new(bytes.Buffer) // enable collection of output
buf = new(bytes.Buffer) // enable collection of output
}
f(buf) // OK
```