-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreferred-pet.go
63 lines (45 loc) · 1.08 KB
/
preferred-pet.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
//package main
import (
"fmt"
"log"
)
func main() {
//uncomment to test without using Payload option
// ARGS["first_name"] = "Bryan"
// ARGS["last_name"] = "Smith"
value, ok := ARGS["first_name"]
if !ok {
log.Println("first_name is required")
return
}
firstName, ok := value.(string)
if !ok {
log.Println("first_name must be a string")
return
}
value, ok = ARGS["last_name"]
if !ok {
log.Println("last_name is required")
return
}
lastName , ok:= value.(string)
if !ok {
log.Println("last_name must be a string")
return
}
var preferred = ""
if len(firstName) > 0 && len(lastName) > 0 {
if (len(firstName)+len(lastName))%2 == 0 {
preferred = "cats"
} else {
preferred = "dogs"
}
}
result := map[string]string{ "preferred": preferred }
resultBytes, err := json.Marshal(result)
if err != nil {
log.Println("failed to serialize result to json")
return
}
fmt.Println(string(resultBytes))
}pe