-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_var_2.go
108 lines (89 loc) · 1.64 KB
/
2_var_2.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
package main
import "fmt"
type profession(type T) interface {
type hr, coder, sales, athlete, lawyer
}
type res struct {
a int
hr1 worker(hr)
coder1 worker(coder)
sales1 worker(sales)
athlete1 worker(athlete)
lawyer1 worker(lawyer)
}
type worker(type T profession) struct {
pers person
specialization T
exp int
}
type person struct {
name string
age int
}
type hr struct {
country string
field string
}
type coder struct {
primaryTech string
secondaryTech string
}
type sales struct {
field string
wins string
}
type athlete struct {
sport string
wins string
}
type lawyer struct {
specialization string
wins string
}
func main() {
/*
a := worker(hr){
person{"Maksym Sydorov", 27},
hr{"Ukraine", "IT"}, 4,
}
fmt.Print(a)
*/
var b res
x := []string{"coder", "Ukraine", "IT"}
b = workerBuilder(person{"Maksym Sydorov", 28}, 5, x)
Print(b)
}
func workerBuilder(pers person, exp int, a []string) (res1 res) {
switch a[0] {
case "hr":
res1.a = 0
res1.hr1 = worker(hr){pers, hr{a[1], a[2]}, exp}
case "coder":
res1.a = 1
res1.coder1 = worker(coder){pers, coder{a[1], a[2]}, exp}
case "sales":
res1.a = 2
res1.sales1 = worker(sales){pers, sales{a[1], a[2]}, exp}
case "athlete":
res1.a = 3
res1.athlete1 = worker(athlete){pers, athlete{a[1], a[2]}, exp}
case "lawyer":
res1.a = 4
res1.lawyer1 = worker(lawyer){pers, lawyer{a[1], a[2]}, exp}
}
return res1
}
func Print(b res) {
switch b.a {
case 0:
fmt.Println(b.hr1)
case 1:
fmt.Println(b.coder1)
case 2:
fmt.Println(b.sales1)
case 3:
fmt.Println(b.athlete1)
case 4:
fmt.Println(b.lawyer1)
}
}