/
app.go
65 lines (59 loc) · 1.39 KB
/
app.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
package helloworldpb
import (
"fmt"
"strings"
)
func PrepareMessage(c *HelloWorldConfiguration) string {
if h := c.GetHello(); h != nil {
return prepareHello(h)
}
if b := c.GetBye(); b != nil {
return prepareBye(b)
}
return "Not command specified: This should not happen due to validation that has to happen on consumer side."
}
func prepareHello(c *HelloCommand) string {
switch c.Lang {
case Lang_POLISH:
msg := fmt.Sprintf("Witam %s świat dla %q w %v roku!", c.World, c.Name, c.Year)
if c.PleaseAddReally || c.AddReally {
return "(naprawdę!) " + msg
}
return msg
case Lang_GERMAN:
return "can't speak German really, contributions welcome ):"
default:
fallthrough
case Lang_ENGLISH:
msg := fmt.Sprintf("Hello %s world for %q in %v year!", c.World, c.Name, c.Year)
if c.PleaseAddReally || c.AddReally {
return "(really!) " + msg
}
return msg
}
}
func prepareJustBye(l Lang) string {
switch l {
case Lang_POLISH:
return "Pa pa świat!"
case Lang_GERMAN:
return "can't speak German really, contributions welcome ):"
default:
fallthrough
case Lang_ENGLISH:
return "See Ya world!"
}
}
func prepareBye(c *ByeCommand) string {
s := prepareJustBye(c.Lang)
if b := c.GetConfigurable(); b != nil {
for _, e := range b.Extra {
s += fmt.Sprint(e)
}
// YOLO
if b.Config.Configs[b.ConfigId].Capitalized {
return strings.ToUpper(s)
}
}
return s
}