mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2025-08-06 23:41:43 +00:00
ch7: fix code format
This commit is contained in:
@@ -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
|
||||
```
|
||||
|
Reference in New Issue
Block a user