-
Notifications
You must be signed in to change notification settings - Fork 0
/
clojure.go
88 lines (68 loc) · 1.58 KB
/
clojure.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
package main
import (
"errors"
"fmt"
)
type UserType map[string]string
var employees = map[int]interface{} {
1: UserType {
"Role": "D",
"Language" : "Go",
},
2: UserType {
"Role": "T",
"Framework" : "Selenium",
},
3: UserType {
"Role": "P",
"Methodology": "Agile",
},
}
type UserLoadResult struct {
User UserType
Error error
}
type UserLoadResultCreator func () (UserLoadResult)
func ComputePrintString(functionToCall UserLoadResultCreator) UserLoadResult {
result := functionToCall()
if (result.Error != nil) {
fmt.Println(result.Error.Error())
}
switch (result.User["Role"]) {
case "D":
result.User["PrintString"] = "Developer likes to code in " + result.User["Language"]
break;
case "T":
result.User["PrintString"] = "Tester likes to test with " + result.User["Framework"]
break;
case "P":
result.User["PrintString"] = "Project manager like to delivery using " + result.User["Methodology"]
break;
default:
break;
}
return result
}
func LoadUser(id int) UserLoadResult {
employee, found := employees[id]
mapToUserLoadResult := func () UserLoadResult {
var invalidIdError error
if (!found) {
invalidIdError = errors.New("No user with the given Id could be found")
}
return UserLoadResult {
User: employee.(UserType),
Error: invalidIdError,
}
}
return ComputePrintString(mapToUserLoadResult)
}
func main() {
outputChannel := make(chan UserLoadResult)
go func() {
outputChannel <- LoadUser(1)
}()
func(loadUserResult UserLoadResult) {
fmt.Println(loadUserResult.User["PrintString"])
}(<- outputChannel)
}