-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStructures.go
60 lines (46 loc) · 902 Bytes
/
Structures.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
)
type Signal struct{}
type User struct {
Id int64
Name string
previous *User
counter *int
test struct {
test string
}
}
var counter int
func NewUser() *User {
counter++
return &User{counter: &counter}
}
func main() {
var John User
var Ivan *User = NewUser()
Ivan.counter = &counter
user3 := NewUser()
user4 := User{123, "asdf", user3, &counter, struct{ test string }{test: "sdf"}}
John.Id = 123
John.Name = "awd"
/* anonymous structure */
var wordCounts []struct {
w string
i int
}
wordCounts = append(wordCounts, struct {
w string
i int
}{w: "qwe", i: 4})
wordCounts = append(wordCounts, struct {
w string
i int
}{w: "sdf", i: 4})
fmt.Println("Structures", John)
fmt.Println("Structures", Ivan)
fmt.Println("Structures", user3)
fmt.Println("Structures", user4)
fmt.Println("Structures", wordCounts)
}