-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
127 lines (108 loc) · 1.99 KB
/
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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"fmt"
)
//func main() {
// var i interface{}
// i = 20
// i = "hello"
// i = struct {
// FirstName string
// LastName string
// }{"Mustafa", "Kemal"}
//
// fmt.Println(i)
//}
//---------//
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
IsFemale bool `json:"isFemale"`
Details struct {
FirstKey string `json:"firstKey"`
SecondKey string `json:"secondKey"`
} `json:"details"`
}
//
//func main() {
//data := map[string]interface{}{}
//contents, err := ioutil.ReadFile("data.json")
//if err != nil {
// panic(err)
//}
//
//if err := json.Unmarshal(contents, &data); err != nil {
// panic(err)
//}
//fmt.Println(data)
//fmt.Println(data["age"].(float64) + 1)
//
//fmt.Println(len(data["name"].(string)))
//
//fmt.Println(!data["isFemale"].(bool))
//
//details := data["details"].(map[string]interface{})
//for _, d := range details {
// fmt.Println(d)
//}
//data := Person{}
//contents, err := ioutil.ReadFile("data.json")
//if err != nil {
// panic(err)
//}
//
//if err := json.Unmarshal(contents, &data); err != nil {
// panic(err)
//}
//
////fmt.Println(data.IsFemale,data.Name,data.Details.SecondKey)
//
//byteData, err := json.Marshal(data)
//if err != nil {
// panic(err)
//}
//
//fmt.Println(byteData)
//fmt.Println(string(byteData))
//}
type Animal interface {
Sound() interface{}
Eat(bool) string
}
type Dog struct {
}
func (d Dog) Sound() interface{} {
return 123
}
func (d Dog) Eat(b bool) string {
return "dog-eat!"
}
type Cat struct {
}
func (c Cat) Sound() interface{} {
return "Miyav!"
}
func (c Cat) Eat(b bool) string {
return "cat-eat!"
}
type Cow struct {
}
func (l Cow) Sound() interface{} {
return "Moo!"
}
func (l Cow) Eat(b bool) string {
return "cow-eat!"
}
// if you got method you are my type
func main() {
animals := []Animal{Dog{}, Cat{}, Cow{}}
//dog:=Dog{}
//dog.Sound()
//
//cat := Cat{}
//cat.Sound()
for _, animal := range animals {
fmt.Println(animal.Sound())
fmt.Println(animal.Eat(true))
}
}