-
Notifications
You must be signed in to change notification settings - Fork 0
/
helloworld.go
45 lines (38 loc) · 1017 Bytes
/
helloworld.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
package main
import (
"flag"
"fmt"
)
type language string
func main() {
var userLang string
//using flag to capture user imput
flag.StringVar(&userLang, "lang", "en", "The required language, e.g. en, heb...")
// fills all flag occurances with the value provided
flag.Parse()
greeting := greet(language(userLang))
fmt.Println(greeting)
}
var phrasebook = map[language]string{
"el": "Χαίρετε Κόσμε", // Greek
"en": "Hello World", // English
"fr": "Bonjor le monde", // French
"heb": "שלום עולם", // Hebrew
"ur": "ہیلو دنیا", // Urdu
"vi": "Xin chào Thế Giới", // Vietnamese
"itl": "Choi", // Italian
}
func greet(l language) string {
// value // bool
greeting, ok := phrasebook[l]
if !ok {
return fmt.Sprintf("unsupported language: %q", l)
}
return greeting
}
func ErrorMessage() {
fmt.Println("Please choose one of the supported languages")
for lang, _ := range phrasebook {
fmt.Printf("%s\n", lang)
}
}