Update go.md

Lazy input with defer, independent of where where its defined in codeland
This commit is contained in:
telluz 2019-04-17 14:08:33 +02:00 committed by GitHub
parent fc41560d71
commit e2d9dc7772
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

14
go.md
View File

@ -422,10 +422,24 @@ func main() {
fmt.Println("Working...")
}
```
{: data-line="2,3,4"}
Lambdas are better suited for defer blocks.
```go
func main() {
var d = int64(0)
defer func(d *int64) {
fmt.Printf("& %v Unix Sec\n", *d)
}(&d)
fmt.Print("Done ")
d = time.Now().Unix()
}
```
{: data-line="3,4,5"}
The defer func uses current value of d, unless we use a pointer to get final value at end of main.
## Structs
{: .-three-column}