35 lines
604 B
Go
35 lines
604 B
Go
|
package main
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
const spanish = "Spanish"
|
||
|
const french = "French"
|
||
|
const englishHelloPrefix = "Hello, "
|
||
|
const spanishHelloPrefix = "Hola, "
|
||
|
const frenchHelloPrefix = "Bonjour, "
|
||
|
|
||
|
func main() {
|
||
|
fmt.Println(Hello("world", ""))
|
||
|
}
|
||
|
|
||
|
func Hello(name string, language string) string {
|
||
|
if name == "" {
|
||
|
name = "World"
|
||
|
}
|
||
|
prefix := greetingPrefix(language)
|
||
|
|
||
|
return prefix + name
|
||
|
}
|
||
|
|
||
|
func greetingPrefix(language string) (prefix string) {
|
||
|
switch language {
|
||
|
case french:
|
||
|
prefix = frenchHelloPrefix
|
||
|
case spanish:
|
||
|
prefix = spanishHelloPrefix
|
||
|
default:
|
||
|
prefix = englishHelloPrefix
|
||
|
}
|
||
|
return
|
||
|
}
|