-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocedural.go
96 lines (77 loc) · 1.75 KB
/
procedural.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
package main
import (
"fmt"
"errors"
)
type EmployeeRole int
const (
Developer EmployeeRole = iota
Tester
ProjectManager
)
var roleMap = map[string]EmployeeRole {
"D" : Developer,
"T" : Tester,
"P" : ProjectManager,
}
var employees = map[int]interface{} {
1: map[string]string {
"Role": "D",
"Language" : "Go",
},
2: map[string]string {
"Role": "T",
"Framework" : "Selenium",
},
3: map[string]string {
"Role": "P",
"Methodology": "Agile",
},
}
func LoadDeveloper(id int) (map[string]string, error) {
return employees[id].(map[string]string), nil
}
func LoadTester(id int) (map[string]string, error) {
return employees[id].(map[string]string), nil
}
func LoadProjectManager(id int) (map[string]string, error) {
return employees[id].(map[string]string), nil
}
func LoadUser(id int) (map[string]string, error) {
if employee, validId := employees[id]; !validId {
return nil, errors.New("Invalid employee id")
} else {
roleAbbreviation := employee.(map[string]string)["Role"]
switch roleMap[roleAbbreviation] {
case Developer:
return LoadDeveloper(id)
case Tester:
return LoadTester(id)
case ProjectManager:
return LoadProjectManager(id)
default:
return nil, errors.New("User loaded but role not catered for");
}
}
}
func PrintUser(user map[string]string) {
switch roleMap[user["Role"]] {
case Developer:
fmt.Println("Developer codes in " + user["Language"])
break;
case Tester:
fmt.Println("Tester tests with " + user["Framework"])
break;
case ProjectManager:
fmt.Println("PM delivers using " + user["Methodology"])
break;
default:
fmt.Println("Role not catered for");
break;
}
}
func main() {
if userData, loadError := LoadUser(1); loadError == nil {
PrintUser(userData)
}
}