-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.go
76 lines (57 loc) · 1.19 KB
/
structs.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import "fmt"
func main() {
myInst := new(myStruct)
myInst.myField = "myVal"
fmt.Println(myInst)
myInst_ := &myStruct{}
myInst_.myField = "myVal"
fmt.Println(myInst_)
myInst__ := newStruct()
myInst__.myMap[1] = 1
fmt.Println(myInst__.myMap)
myAddInst := newAddStruct([]int{1, 2, 3, 4, 5, 6, 7})
fmt.Println(myAddInst.findSum(11))
sayInit()
}
func sayInit() {
myStruct_ := compostStructChild{compostStructParent{"Val1", "Val2"}, "Val1.1"}
myStruct_.print()
}
type myStruct struct {
myField string
myMap map[int]int
}
func newStruct() *myStruct {
result := &myStruct{}
result.myMap = make(map[int]int)
return result
}
type addStruct struct {
arr [7]int
}
func newAddStruct(arr []int) *addStruct {
flagStruct := new(addStruct)
for i := 0; i < 7; i++ {
flagStruct.arr[i] = arr[i]
}
return flagStruct
}
func (asp *addStruct) findSum(offSet int) int {
result := 0
for _, val := range asp.arr {
result += val
}
return result + offSet
}
type compostStructParent struct {
myField_ string
myField__ string
}
type compostStructChild struct {
compostStructParent
myField__ string
}
func (sp *compostStructChild) print() {
fmt.Println(sp.myField_, sp.myField__)
}