Merge pull request #1072 from telluz/patch-1

Update go.md
This commit is contained in:
Rico Sta. Cruz 2019-12-18 13:43:43 +11:00 committed by GitHub
commit e3f165a90b
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...") fmt.Println("Working...")
} }
``` ```
{: data-line="2,3,4"} {: data-line="2,3,4"}
Lambdas are better suited for defer blocks. 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 ## Structs
{: .-three-column} {: .-three-column}