gotdd/hello.go

35 lines
604 B
Go
Raw Permalink Normal View History

2022-01-20 04:20:12 +00:00
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
}