-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
35 lines (27 loc) · 785 Bytes
/
main.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
// Composite Literals is the Go wording for explicit
// initialization of structs, slices, arrays, maps
package main
import "fmt"
type subTest struct {
a string
b []int
c map[int]int
}
type test struct {
st []subTest
}
func main() {
// Simple Composite Literals
aSlice := []int{1, 2, 3}
aMap := map[int]int{1: 1, 2: 2, 3: 3}
aArray := [...]string{"a", "b", "c"}
fmt.Println("Slice:", aSlice)
fmt.Println("Map: ", aMap)
fmt.Println("Array: ", aArray)
// A bit more complex
st := subTest{"a string", []int{1, 2}, map[int]int{1: 1, 2: 2, 3: 3}}
fmt.Println("Struct:", st)
// Two-Level, complex
t := test{[]subTest{{"a string", []int{1, 2}, map[int]int{1: 1, 2: 2, 3: 3}}, {"a string", []int{3, 4}, map[int]int{4: 4, 5: 5, 6: 6}}}}
fmt.Println("Two-Level: ", t)
}