-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.go
60 lines (49 loc) · 1.15 KB
/
hello.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
package main
import "fmt"
// Public Language Constants
const English = "english"
const Spanish = "spanish"
const French = "french"
// Private Hello Prefix translations
const helloEnglishPrefix = "Hello, "
const helloSpanishPrefix = "Hola, "
const helloFrenchPrefix = "Bonjour, "
// Private World translations
const worldEnglish = "World"
const worldSpanish = "Mundo"
const worldFrench = "Munde"
// Get the language tranlation prefix
func getPrefix(language string) string {
switch language {
case English:
return helloEnglishPrefix
case Spanish:
return helloSpanishPrefix
case French:
return helloFrenchPrefix
}
return helloEnglishPrefix
}
// Get the "World" language tranlation
func getWorld(language string) string {
switch language {
case English:
return worldEnglish
case Spanish:
return worldSpanish
case French:
return worldFrench
}
return worldEnglish
}
// Return the Greeting with name or "World" based on tranlation language
func Hello(name string, language string) string {
if name == "" {
name = getWorld(language)
}
return getPrefix(language) + name
}
// Main function
func main() {
fmt.Println(Hello("Robert", English))
}