Introduce anonymous structs (#474)

This commit is contained in:
Hossein Naghdbishi
2023-06-05 12:40:49 +00:00
committed by GitHub
parent 1512fb0094
commit 4b9411514f
4 changed files with 41 additions and 7 deletions

View File

@@ -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)
}

View File

@@ -1,2 +1,2 @@
f1dcc357b5e20c3aa3a97df8245efe4aea7940d6
n7jt1x3iw4Z
5a15014159c5c98fe5f829c483ded3914db77053
D9lW-Dd6XQP

View File

@@ -6,4 +6,5 @@ $ go run structs.go
&{Jon 42}
Sean
50
51
51
{Rex true}