Introduce anonymous structs (#474)
This commit is contained in:
committed by
GitHub
parent
1512fb0094
commit
4b9411514f
@@ -50,4 +50,15 @@ func main() {
|
||||
// Structs are mutable.
|
||||
sp.age = 51
|
||||
fmt.Println(sp.age)
|
||||
|
||||
// Structs don't always have to be defined as instances of types,
|
||||
// you can define a struct anonymously.
|
||||
dog := struct {
|
||||
name string
|
||||
isGood bool
|
||||
}{
|
||||
"Rex",
|
||||
true,
|
||||
}
|
||||
fmt.Println(dog)
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
f1dcc357b5e20c3aa3a97df8245efe4aea7940d6
|
||||
n7jt1x3iw4Z
|
||||
5a15014159c5c98fe5f829c483ded3914db77053
|
||||
D9lW-Dd6XQP
|
||||
|
||||
@@ -6,4 +6,5 @@ $ go run structs.go
|
||||
&{Jon 42}
|
||||
Sean
|
||||
50
|
||||
51
|
||||
51
|
||||
{Rex true}
|
||||
|
||||
Reference in New Issue
Block a user