51 lines
947 B
Go
Raw Normal View History

2024-09-10 11:47:40 +02:00
package helloworld
2024-09-10 11:06:51 +02:00
2024-09-10 11:16:15 +02:00
const (
2024-09-10 11:35:30 +02:00
english = "English"
spanish = "Spanish"
2024-09-10 11:44:21 +02:00
)
2024-09-10 11:35:30 +02:00
2024-09-10 11:44:21 +02:00
var (
helloPrefixMap map[string]string
defaultWorldMap map[string]string
2024-09-10 11:16:15 +02:00
)
2024-09-10 11:44:21 +02:00
func initDefaults() {
initPrefixMap()
initWorldMap()
}
2024-09-10 11:35:30 +02:00
2024-09-10 11:44:21 +02:00
func initPrefixMap() {
helloPrefixMap = make(map[string]string)
helloPrefixMap[english] = "Hello "
helloPrefixMap[spanish] = "Hola "
}
func initWorldMap() {
defaultWorldMap = make(map[string]string)
defaultWorldMap[english] = "world"
defaultWorldMap[spanish] = "Mundo"
}
func getDefaultWorldByLanguage(language string) string {
return defaultWorldMap[language]
2024-09-10 11:35:30 +02:00
}
func getHelloPrefixByLanguage(language string) string {
2024-09-10 11:44:21 +02:00
return helloPrefixMap[language]
2024-09-10 11:35:30 +02:00
}
func Hello(name, language string) string {
prefix := getHelloPrefixByLanguage(language)
2024-09-10 11:12:42 +02:00
if name == "" {
2024-09-10 11:35:30 +02:00
return prefix + getDefaultWorldByLanguage(language)
2024-09-10 11:12:42 +02:00
}
2024-09-10 11:35:30 +02:00
return prefix + name
2024-09-10 11:06:51 +02:00
}
2024-09-10 11:47:40 +02:00
// func main() {
// initDefaults()
// fmt.Println(Hello("Mary", "English"))
// }